home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / bfl / bfl.lha / cfortran.h < prev    next >
C/C++ Source or Header  |  1992-10-28  |  72KB  |  1,527 lines

  1. /* cfortran.h */ /* 2.4 */            /* anonymous ftp: zebra.desy.de */
  2. /* Burkhard Burow, burow@vxdesy.cern.ch, University of Toronto, 1992. */
  3.  
  4. #ifndef __CFORTRAN_LOADED
  5. #define __CFORTRAN_LOADED
  6.  
  7. /* 
  8.    THIS FILE IS PROPERTY OF BURKHARD BUROW. IF YOU ARE USING THIS FILE YOU
  9.    SHOULD ALSO HAVE ACCESS TO CFORTRAN.DOC WHICH PROVIDES TERMS FOR USING,
  10.    MODIFYING, COPYING AND DISTRIBUTING THE CFORTRAN.H PACKAGE.
  11. */
  12.  
  13. /* Before using cfortran.h on CRAY, RS/6000, Apollo >=6.8, gcc -ansi,
  14.    or any other ANSI C compiler, you must once do:
  15. prompt> mv cfortran.h cf_temp.h && sed 's/\/\*\*\//##/g' cf_temp.h >cfortran.h
  16.    i.e. we change the ' / * * / ' kludge to ##. */
  17.  
  18. /* First prepare for the C compiler. */
  19.  
  20. #if (defined(vax)&&defined(unix)) || (defined(__vax__)&&defined(__unix__))
  21. #define VAXUltrix
  22. #endif
  23.  
  24. #include <stdio.h>     /* NULL [in all machines stdio.h]                      */
  25. #include <string.h>    /* strlen, memset, memcpy, memchr.                     */
  26. #if !( defined(VAXUltrix) || defined(sun) || (defined(apollo)&&!defined(__STDCPP__)) )
  27. #include <stdlib.h>    /* malloc,free                                         */
  28. #else
  29. #include <malloc.h>    
  30. #ifdef apollo
  31. #define __CF__APOLLO67 /* __STDCPP__ is in Apollo 6.8 (i.e. ANSI) and onwards */
  32. #endif
  33. #endif
  34.  
  35. #if (!defined(__GNUC__) && (defined(__hp9000s300)||defined(sun)||defined(VAXUltrix)||defined(lynx)))
  36. #define __CF__KnR     /* HP, Sun, LynxOS and VAX Ultrix cc only supports K&R. */
  37. #endif                /*       i.e. We will generate Kernighan and Ritchie C. */
  38. /* Note that you may define __CF__KnR before #include cfortran.h, in order to
  39. generate K&R C instead of the default ANSI C. The differences are mainly in the
  40. function prototypes and declarations. All machines, except the Apollo, work
  41. with either style. The Apollo's argument promotion rules require ANSI or use of
  42. the obsolete std_$call which we have not implemented here. Hence on the Apollo,
  43. only C calling FORTRAN subroutines will work using K&R style.*/
  44.  
  45.  
  46. /* Remainder of cfortran.h depends on the Fortran compiler. */
  47.  
  48. /* VAX/VMS does not let us \-split these long lines. */ 
  49. #if !(defined(NAGf90Fortran)||defined(f2cFortran)||defined(hp9000s300Fortran)||defined(apolloFortran)||defined(sunFortran)||defined(IBMR2Fortran)||defined(CRAYFortran)||defined(mipsFortran)||defined(DECFortran)||defined(vmsFortran))
  50. /* If no Fortran compiler is given, we choose one for the machines we know.   */
  51. #if defined(lynx) || defined(VAXUltrix)
  52. #define f2cFortran    /* Lynx:      Only support f2c at the moment.
  53.                          VAXUltrix: f77 behaves like f2c.
  54.                            Support f2c or f77 with gcc, vcc with f2c. 
  55.                            f77 with vcc works, missing link magic for f77 I/O.*/
  56. #endif
  57. #if defined(__hp9000s300)
  58. #define       hp9000s300Fortran
  59. #endif
  60. #if       defined(apollo)
  61. #define           apolloFortran  /* __CF__APOLLO67 defines some behavior. */
  62. #endif
  63. #if          defined(sun)
  64. #define              sunFortran
  65. #endif
  66. #if       defined(_IBMR2)
  67. #define            IBMR2Fortran
  68. #endif
  69. #if        defined(_CRAY)
  70. #define             CRAYFortran  /* _CRAY2         defines some behavior. */
  71. #endif
  72. #if         defined(mips) || defined(__mips)
  73. #define             mipsFortran
  74. #endif
  75. #if          defined(vms)
  76. #define              vmsFortran
  77. #endif
  78. #endif /* ...Fortran */
  79.  
  80. #if !(defined(NAGf90Fortran)||defined(f2cFortran)||defined(hp9000s300Fortran)||defined(apolloFortran)||defined(sunFortran)||defined(IBMR2Fortran)||defined(CRAYFortran)||defined(mipsFortran)||defined(DECFortran)||defined(vmsFortran))
  81. ??=error cfortran.h supports the following machines/OS/compilers:
  82. ??=error - MIPS cc and f77 2.0. (e.g. Silicon Graphics, DECstations, ...)
  83. ??=error - IBM AIX XL C and FORTRAN Compiler/6000 Version 01.01.0000.0000
  84. ??=error - VAX VMS CC 3.1 and FORTRAN 5.4.
  85. ??=error - Apollo DomainOS 10.2 (sys5.3) with f77 10.7 and cc 6.7.
  86. ??=error - CRAY
  87. ??=error - Sun
  88. ??=error - HP9000s300
  89. ??=error - LynxOS: cc or gcc with f2c.
  90. ??=error - VAX Ultrix: vcc,cc or gcc with f2c. gcc or cc with f77.
  91. ??=error -             f77 with vcc works; but missing link magic for f77 I/O.
  92. ??=error -             NO fort. None of gcc, cc or vcc generate required names.
  93. ??=error - f2c    : Use #define    f2cFortran, or cc -Df2cFortran
  94. ??=error - NAG f90: Use #define NAGf90Fortran, or cc -DNAGf90Fortran
  95. #else   /* #endif is 2nd last line of file. */
  96.  
  97. /* Throughout cfortran.h we use: UN = Uppercase Name.  LN = Lowercase Name.  */
  98.  
  99. #if defined(f2cFortran) || defined(NAGf90Fortran) || defined(DECFortran) || defined(mipsFortran) || defined(apolloFortran) || defined(sunFortran) || (defined(IBMR2Fortran) && defined(extname))
  100. #define CFC_(UN,LN)            LN/**/_   /* Lowercase FORTRAN symbols.        */
  101. #define orig_fcallsc           CFC_
  102. #else 
  103. #ifdef CRAYFortran
  104. #define CFC_(UN,LN)            UN        /* Uppercase FORTRAN symbols.        */
  105. #define orig_fcallsc(UN,LN)    CFC_(UN,LN)  /* CRAY insists on arg.'s here.   */
  106. #else  /* For following machines one may wish to change the fcallsc default.  */
  107. #define CF_SAME_NAMESPACE
  108. #ifdef vmsFortran
  109. #pragma nostandard                       /* To avoid %CC-I-PARAMNOTUSED.      */
  110. #define CFC_(UN,LN)            LN        /* Either case FORTRAN symbols.      */
  111.      /* BUT we usually use UN for C macro to FORTRAN routines, so use LN here,*/
  112.      /* because VAX/VMS doesn't do recursive macros.                          */
  113. #define orig_fcallsc(UN,LN)    UN      
  114. #pragma standard                         /* Have avoided %CC-I-PARAMNOTUSED.  */
  115. #else                   /* HP, or IBMR2&&!-qextname which isn't reccomended.  */
  116. #define CFC_(UN,LN)            LN        /* Lowercase FORTRAN symbols.        */
  117. #define orig_fcallsc           CFC_
  118. #endif /*  vmsFortran */
  119. #endif /* CRAYFortran */
  120. #endif /* ....Fortran */
  121.  
  122. #define fcallsc                      orig_fcallsc
  123. #define preface_fcallsc(P,p,UN,LN)   CFC_(P/**/UN,p/**/LN)
  124. #define  append_fcallsc(P,p,UN,LN)   CFC_(UN/**/P,LN/**/p)
  125.  
  126. #define C_FUNCTION                   fcallsc      
  127. #define FORTRAN_FUNCTION             CFC_
  128. #define COMMON_BLOCK                 CFC_
  129.  
  130. #if defined(NAGf90Fortran) || defined(f2cFortran) || defined(mipsFortran)
  131. #define LOGICAL_STRICT      /* These have .eqv./.neqv. == .eq./.ne.   */
  132. #endif
  133.  
  134. #ifdef CRAYFortran
  135. #if _CRAY
  136. #include <fortran.h>
  137. #else
  138. #include "fortran.h"  /* i.e. if crosscompiling assume user has file. */
  139. #endif
  140. #define DOUBLE_PRECISION long double
  141. #define PPFLOATVV (float *)/* Used for C calls FORTRAN. CRAY's double==float but
  142.                             CRAY says pointers to doubles and floats are diff.*/
  143. #define VOIDP  (void *)  /* When FORTRAN calls C, we don't know if C routine 
  144.                             arg.'s have been declared float *, or double *.   */
  145. #else
  146. #define DOUBLE_PRECISION double
  147. #define PPFLOATVV
  148. #define VOIDP
  149. #endif
  150.  
  151. #ifdef vmsFortran
  152. #if    vms
  153. #include <descrip.h>
  154. #else
  155. #include "descrip.h"  /* i.e. if crosscompiling assume user has file. */
  156. #endif
  157. #endif
  158.  
  159. #ifdef sunFortran
  160. #if    sun
  161. #include <math.h>     /* Sun's FLOATFUNCTIONTYPE, ASSIGNFLOAT, RETURNFLOAT.  */
  162. #else
  163. #include "math.h"     /* i.e. if crosscompiling assume user has file. */
  164. #endif
  165. #endif
  166.  
  167. #ifndef apolloFortran
  168. #define COMMON_BLOCK_DEF(DEFINITION, NAME) extern DEFINITION NAME
  169. #define CF_NULL_PROTO
  170. #else                                         /* HP doesn't understand #elif. */
  171. /* Without ANSI prototyping, Apollo promotes float functions to double.    */
  172. /* Note that VAX/VMS, IBM, Mips choke on 'type function(...);' prototypes. */
  173. #define CF_NULL_PROTO ...
  174. #ifndef __CF__APOLLO67
  175. #define COMMON_BLOCK_DEF(DEFINITION, NAME) \
  176.  DEFINITION NAME __attribute((__section(NAME)))
  177. #else
  178. #define COMMON_BLOCK_DEF(DEFINITION, NAME) \
  179.  DEFINITION NAME #attribute[section(NAME)]
  180. #endif
  181. #endif
  182.  
  183. #ifdef mipsFortran
  184. #define CF_DECLARE_GETARG         int f77argc; char **f77argv
  185. #define CF_SET_GETARG(ARGC,ARGV)  f77argc = ARGC; f77argv = ARGV
  186. #else
  187. #if defined(VAXC) && defined(vms)        
  188. #pragma nostandard                       /* To avoid %CC-I-PARAMNOTUSED.      */
  189. #endif
  190. #define CF_DECLARE_GETARG
  191. #define CF_SET_GETARG(ARGC,ARGV)
  192. #if defined(VAXC) && defined(vms)        
  193. #pragma standard                         /* Have avoided %CC-I-PARAMNOTUSED.  */
  194. #endif
  195. #endif
  196.  
  197. #define ACOMMA ,
  198. #define ACOLON ;
  199.  
  200. /*-------------------------------------------------------------------------*/
  201.  
  202. /*               UTILITIES USED WITHIN CFORTRAN.H                          */
  203.  
  204. #define MIN(A,B) (A<B?A:B)
  205. #define firstindexlength( A) (sizeof(A)     /sizeof(A[0]))
  206. #define secondindexlength(A) (sizeof((A)[0])/sizeof((A)[0][0]))
  207. #ifndef FALSE
  208. #define FALSE (1==0)
  209. #endif
  210.  
  211. /* Behavior of FORTRAN LOGICAL. All machines' LOGICAL is same size as C's int.
  212. Conversion is automatic except for arrays which require F2CLOGICALV/C2FLOGICALV.
  213. f2c, MIPS f77 [DECstation, SGI], VAX Ultrix f77, CRAY-2, HP-UX f77:  as in C.
  214. VAX/VMS FORTRAN, VAX Ultrix fort, IBM RS/6000 xlf: LS Bit = 0/1 = TRUE/FALSE.
  215. Apollo, non CRAY-2                               : neg.   = TRUE, else FALSE. 
  216. [Apollo accepts -1 as TRUE for function values, but NOT all other neg. values.]
  217. [DECFortran for Ultrix RISC is also called f77 but is the same as VAX/VMS.]   
  218. [MIPS f77 treats .eqv./.neqv. as .eq./.ne. and hence requires LOGICAL_STRICT.]*/
  219.  
  220. #define C2FLOGICALV(A,I) \
  221.  do {int __i; for(__i=0;__i<I;__i++) A[__i]=C2FLOGICAL(A[__i]); } while (FALSE)
  222. #define F2CLOGICALV(A,I) \
  223.  do {int __i; for(__i=0;__i<I;__i++) A[__i]=F2CLOGICAL(A[__i]); } while (FALSE)
  224.  
  225. #if defined(apolloFortran) || (defined(CRAYFortran) && !defined(_CRAY2))
  226. #ifndef apolloFortran
  227. #define C2FLOGICAL(L) ((L)?(L)|(1<<sizeof(int)*8-1):(L)&~(1<<sizeof(int)*8-1))
  228. #else
  229. #define C2FLOGICAL(L) ((L)?-1:(L)&~(1<<sizeof(int)*8-1)) /* Apollo Exception  */
  230. #endif
  231. #define F2CLOGICAL(L) ((L)<0?(L):0) 
  232. #else
  233. #if defined(IBMR2Fortran) || defined(vmsFortran) || defined(DECFortran)
  234. #define C2FLOGICAL(L) ((L)?(L)|1:(L)&~(int)1)
  235. #define F2CLOGICAL(L) ((L)&1?(L):0)
  236. #else /* all other machines evaluate LOGICALs as C does. */
  237. #define C2FLOGICAL(L) (L)
  238. #define F2CLOGICAL(L) (L)
  239. #ifndef LOGICAL_STRICT
  240. #undef  C2FLOGICALV
  241. #undef  F2CLOGICALV
  242. #define C2FLOGICALV(A,I)
  243. #define F2CLOGICALV(A,I)
  244. #endif  /* LOGICAL_STRICT */
  245. #endif
  246. #endif
  247.  
  248. #ifdef LOGICAL_STRICT
  249. /* Force C2FLOGICAL to generate only the values for either .TRUE. or .FALSE.
  250.    This is only needed if you want to do:
  251.      logical lvariable
  252.      if (lvariable .eq.  .true.) then       ! (1)
  253.    instead of
  254.      if (lvariable .eqv. .true.) then       ! (2)
  255.    - (1) may not even be FORTRAN/77 and that Apollo's f77 and IBM's xlf
  256.    refuse to compile (1), so you are probably well advised to stay away from 
  257.    (1) and from LOGICAL_STRICT.
  258.    - You pay a (slight) performance penalty for using LOGICAL_STRICT. */
  259. #undef C2FLOGICAL
  260. #if defined(apolloFortran) || (defined(CRAYFortran) && !defined(_CRAY2)) || defined(vmsFortran) || defined(DECFortran)
  261. #define C2FLOGICAL(L) ((L)?-1:0) /* These machines use -1/0 for .true./.false.*/
  262. #else
  263. #define C2FLOGICAL(L) ((L)? 1:0) /* All others     use +1/0 for .true./.false.*/
  264. #endif
  265. #endif /* LOGICAL_STRICT */
  266.  
  267. /* Convert a vector of C strings into FORTRAN strings. */
  268. #ifndef __CF__KnR
  269. static char *c2fstrv(char* cstr, char *fstr, int elem_len, int sizeofcstr)
  270. #else
  271. static char *c2fstrv(      cstr,       fstr,     elem_len,     sizeofcstr)
  272.                      char* cstr; char *fstr; int elem_len; int sizeofcstr;
  273. #endif
  274. { int i,j;
  275. /* elem_len includes \0 for C strings. Fortran strings don't have term. \0.
  276.    Useful size of string must be the same in both languages. */
  277. for (i=0; i<sizeofcstr/elem_len; i++) {
  278.   for (j=1; j<elem_len && *cstr; j++) *fstr++ = *cstr++;
  279.   cstr += 1+elem_len-j;
  280.   for (; j<elem_len; j++) *fstr++ = ' ';
  281. } return fstr-sizeofcstr+sizeofcstr/elem_len; }
  282.  
  283. /* Convert a vector of FORTRAN strings into C strings. */
  284. #ifndef __CF__KnR
  285. static char *f2cstrv(char *fstr, char* cstr, int elem_len, int sizeofcstr)
  286. #else
  287. static char *f2cstrv(      fstr,       cstr,     elem_len,     sizeofcstr)
  288.                      char *fstr; char* cstr; int elem_len; int sizeofcstr; 
  289. #endif
  290. { int i,j;
  291. /* elem_len includes \0 for C strings. Fortran strings don't have term. \0.
  292.    Useful size of string must be the same in both languages. */
  293. cstr += sizeofcstr;
  294. fstr += sizeofcstr - sizeofcstr/elem_len;
  295. for (i=0; i<sizeofcstr/elem_len; i++) {
  296.   *--cstr = '\0';
  297.   for (j=1; j<elem_len; j++) *--cstr = *--fstr;
  298. } return cstr; }
  299.  
  300. /* kill the trailing char t's in string s. */
  301. #ifndef __CF__KnR
  302. static char *kill_trailing(char *s, char t)
  303. #else
  304. static char *kill_trailing(      s,      t) char *s; char t;
  305. #endif
  306. {char *e; 
  307. e = s + strlen(s);
  308. if (e>s) {                           /* Need this to handle NULL string.*/
  309.   while (e>s && *--e==t);            /* Don't follow t's past beginning. */
  310.   e[*e==t?0:1] = '\0';               /* Handle s[0]=t correctly.       */
  311. } return s; }
  312.  
  313. /* kill_trailingn(s,t,e) will kill the trailing t's in string s. e normally 
  314. points to the terminating '\0' of s, but may actually point to anywhere in s.
  315. s's new '\0' will be placed at e or earlier in order to remove any trailing t's.
  316. If e<s string s is left unchanged. */ 
  317. #ifndef __CF__KnR
  318. static char *kill_trailingn(char *s, char t, char *e)
  319. #else
  320. static char *kill_trailingn(      s,      t,       e) char *s; char t; char *e;
  321. #endif
  322. if (e==s) *e = '\0';                 /* Kill the string makes sense here.*/
  323. else if (e>s) {                      /* Watch out for neg. length string.*/
  324.   while (e>s && *--e==t);            /* Don't follow t's past beginning. */
  325.   e[*e==t?0:1] = '\0';               /* Handle s[0]=t correctly.       */
  326. } return s; }
  327.  
  328. /* Note the following assumes that any element which has t's to be chopped off,
  329. does indeed fill the entire element. */
  330. #ifndef __CF__KnR
  331. static char *vkill_trailing(char* cstr, int elem_len, int sizeofcstr, char t)
  332. #else
  333. static char *vkill_trailing(      cstr,     elem_len,     sizeofcstr,      t)
  334.                             char* cstr; int elem_len; int sizeofcstr; char t;
  335. #endif
  336. { int i;
  337. for (i=0; i<sizeofcstr/elem_len; i++) /* elem_len includes \0 for C strings. */
  338.   kill_trailingn(cstr+elem_len*i,t,cstr+elem_len*(i+1)-1);
  339. return cstr; }
  340.  
  341. #ifdef vmsFortran
  342. typedef struct dsc$descriptor_s fstring;
  343. #define DSC$DESCRIPTOR_A(DIMCT)                                         \
  344. struct {                                                                       \
  345.   unsigned short dsc$w_length;            unsigned char     dsc$b_dtype;           \
  346.   unsigned char     dsc$b_class;                     char    *dsc$a_pointer;           \
  347.            char     dsc$b_scale;            unsigned char     dsc$b_digits;         \
  348.   struct {                                                                     \
  349.     unsigned               : 3;      unsigned dsc$v_fl_binscale : 1;      \
  350.     unsigned dsc$v_fl_redim    : 1;       unsigned dsc$v_fl_column   : 1;      \
  351.     unsigned dsc$v_fl_coeff    : 1;       unsigned dsc$v_fl_bounds   : 1;      \
  352.   } dsc$b_aflags;                                                           \
  353.   unsigned char     dsc$b_dimct;            unsigned long     dsc$l_arsize;           \
  354.            char    *dsc$a_a0;                     long     dsc$l_m [DIMCT];      \
  355.   struct {                                                                     \
  356.     long dsc$l_l;                         long dsc$l_u;                        \
  357.   } dsc$bounds [DIMCT];                                                        \
  358. }
  359. typedef DSC$DESCRIPTOR_A(1) fstringvector;
  360. /*typedef DSC$DESCRIPTOR_A(2) fstringarrarr;
  361.   typedef DSC$DESCRIPTOR_A(3) fstringarrarrarr;*/
  362. #define initfstr(F,C,ELEMNO,ELEMLEN)                                           \
  363. ( (F).dsc$l_arsize=  ( (F).dsc$w_length                        =(ELEMLEN) )    \
  364.                     *( (F).dsc$l_m[0]=(F).dsc$bounds[0].dsc$l_u=(ELEMNO)  ),   \
  365.   (F).dsc$a_a0    =  ( (F).dsc$a_pointer=(C) ) - (F).dsc$w_length          ,(F))
  366.  
  367. #define F2CSTRVCOPY(C,F)                                                       \
  368.   vkill_trailing(f2cstrv(F->dsc$a_pointer,C,F->dsc$w_length+1,                 \
  369.                          F->dsc$l_m[0]*(F->dsc$w_length+1)),                   \
  370.                  F->dsc$w_length+1,F->dsc$l_m[0]*(F->dsc$w_length+1),' ')
  371. #define C2FSTRVCOPY(C,F) c2fstrv(C,F->dsc$a_pointer,F->dsc$w_length+1,         \
  372.                                  F->dsc$l_m[0]*(F->dsc$w_length+1)    )
  373.  
  374. #else
  375. #define _NUM_ELEMS      -1
  376. #define _NUM_ELEM_ARG   -2
  377. #define NUM_ELEMS(A)    A,_NUM_ELEMS
  378. #define NUM_ELEM_ARG(B) *A/**/B,_NUM_ELEM_ARG
  379. #define TERM_CHARS(A,B) A,B
  380. #ifndef __CF__KnR
  381. static int num_elem(char *strv, unsigned elem_len, int term_char, int num_term)
  382. #else
  383. static int num_elem(      strv,          elem_len,     term_char,     num_term)
  384.                     char *strv; unsigned elem_len; int term_char; int num_term;
  385. #endif
  386. /* elem_len is the number of characters in each element of strv, the FORTRAN
  387. vector of strings. The last element of the vector must begin with at least
  388. num_term term_char characters, so that this routine can determine how 
  389. many elements are in the vector. */
  390. {
  391. unsigned num,i;
  392. if (num_term == _NUM_ELEMS || num_term == _NUM_ELEM_ARG) 
  393.   return term_char;
  394. if (num_term <=0) num_term = elem_len;
  395. for (num=0; ; num++) {
  396.   for (i=0; i<num_term && *strv==term_char; i++,strv++);
  397.   if (i==num_term) break;
  398.   else strv += elem_len-i;
  399. }
  400. return num;
  401. }
  402. #endif
  403. /*-------------------------------------------------------------------------*/
  404.  
  405. /*           UTILITIES FOR C TO USE STRINGS IN FORTRAN COMMON BLOCKS       */
  406.  
  407. /* C string TO Fortran Common Block STRing. */
  408. /* DIM is the number of DIMensions of the array in terms of strings, not
  409.    characters. e.g. char a[12] has DIM = 0, char a[12][4] has DIM = 1, etc. */
  410. #define C2FCBSTR(CSTR,FSTR,DIM)                                                \
  411.  c2fstrv((char *)CSTR, (char *)FSTR, sizeof(FSTR)/cfelementsof(FSTR,DIM)+1,    \
  412.          sizeof(FSTR)+cfelementsof(FSTR,DIM))
  413.  
  414. /* Fortran Common Block string TO C STRing. */
  415. #define FCB2CSTR(FSTR,CSTR,DIM)                                                \
  416.  vkill_trailing(f2cstrv((char *)FSTR, (char *)CSTR,                            \
  417.                         sizeof(FSTR)/cfelementsof(FSTR,DIM)+1,                 \
  418.                         sizeof(FSTR)+cfelementsof(FSTR,DIM)),                  \
  419.                 sizeof(FSTR)/cfelementsof(FSTR,DIM)+1,                         \
  420.                 sizeof(FSTR)+cfelementsof(FSTR,DIM), ' ')
  421.  
  422. #define cfDEREFERENCE0
  423. #define cfDEREFERENCE1 *
  424. #define cfDEREFERENCE2 **
  425. #define cfDEREFERENCE3 ***
  426. #define cfDEREFERENCE4 ****
  427. #define cfDEREFERENCE5 *****
  428. #define cfelementsof(A,D) (sizeof(A)/sizeof(cfDEREFERENCE/**/D(A)))
  429.  
  430. /*-------------------------------------------------------------------------*/
  431.  
  432. /*               UTILITIES FOR C TO CALL FORTRAN SUBROUTINES               */
  433.  
  434. /* Define lookup tables for how to handle the various types of variables.  */
  435.  
  436. #if defined(VAXC) && defined(vms)        /* To avoid %CC-I-PARAMNOTUSED. */
  437. #pragma nostandard
  438. #endif
  439.  
  440. static int __cfztringv[30];       /* => 30 == MAX # of arg.'s C can pass to a */
  441. #define ZTRINGV_NUM(I) I          /*          FORTRAN function.               */
  442. #define ZTRINGV_ARGF(I) __cfztringv[I]
  443. #define ZTRINGV_ARGS(I) B/**/I
  444.  
  445. #define VPPBYTE         VPPINT
  446. #define VPPDOUBLE       VPPINT
  447. #define VPPFLOAT        VPPINT
  448. #define VPPINT(    A,B) int  B = (int)A;   /* For ZSTRINGV_ARGS */
  449. #define VPPLOGICAL(A,B) int *B;         /* Returning LOGICAL in FUNn and SUBn.*/
  450. #define VPPLONG         VPPINT
  451. #define VPPSHORT        VPPINT
  452.  
  453. #define VCF(TN,I)       _INT(3,V,TN,A/**/I,B/**/I)
  454. #define VVCF(TN,AI,BI)  _INT(3,V,TN,AI,BI)
  455. #define VINT(     T,A,B) typeP/**/T/**/VV B = A;
  456. #define VINTV(    T,A,B) typeP/**/T/**/V *B = PP/**/T/**/V A;
  457. #define VINTVV(   T,A,B) typeP/**/T      *B = PP/**/T      A[0];
  458. #define VPINT(    T,A,B) VP/**/T(A,B)
  459. #define VPVOID(   T,A,B)
  460. #define VSIMPLE(  T,A,B)
  461. #ifdef vmsFortran
  462. #define VSTRING(  T,A,B) static struct {fstring f; unsigned clen;} B =         \
  463.                                        {{0,DSC$K_DTYPE_T,DSC$K_CLASS_S,NULL},0};
  464. #define VPSTRING( T,A,B) static fstring B={0,DSC$K_DTYPE_T,DSC$K_CLASS_S,NULL};
  465. #define VSTRINGV( T,A,B) static fstringvector B =                              \
  466. {sizeof(A),DSC$K_DTYPE_T,DSC$K_CLASS_A,NULL,0,0,{0,0,0,1,1,1},1,0,NULL,0,{1,0}};
  467. #define VPSTRINGV(T,A,B) static fstringvector B =                              \
  468. {0,DSC$K_DTYPE_T,DSC$K_CLASS_A,NULL,0,0,{0,0,0,1,1,1},1,0,NULL,0,{1,0}};
  469. #else
  470. #define VSTRING(  T,A,B) struct {unsigned short clen, flen;} B;
  471. #define VSTRINGV( T,A,B) struct {char *s, *fs; unsigned flen;} B;
  472. #define VPSTRING( T,A,B) int     B;
  473. #define VPSTRINGV(T,A,B) struct {char *fs; unsigned short sizeofA, flen;} B;
  474. #endif
  475. #define VZTRINGV         VSTRINGV
  476. #define VPZTRINGV        VPSTRINGV
  477.  
  478. /* Note that the actions of the A table were performed inside the AA table.
  479.    VAX Ultrix vcc, and HP-UX cc, didn't evaluate arguments to functions left to
  480.    right, so we had to split the original table into the current robust two. */
  481. #define ACF(NAME,TN,AI,I)  STR_/**/TN(4,A,NAME,I,AI,B/**/I)
  482. #define ALOGICAL( M,I,A,B) B=C2FLOGICAL(B);
  483. #define APLOGICAL(M,I,A,B) A=C2FLOGICAL(A);
  484. #define ASTRING(  M,I,A,B) CSTRING(A,B,sizeof(A))
  485. #define APSTRING( M,I,A,B) CPSTRING(A,B,sizeof(A))
  486. #ifdef vmsFortran
  487. #define AATRINGV( M,I,A,B, sA,filA,silA)                                       \
  488.  initfstr(B,malloc((sA)-(filA)),(filA),(silA)-1),                              \
  489.           c2fstrv(A[0],B.dsc$a_pointer,(silA),(sA));
  490. #define APATRINGV(M,I,A,B, sA,filA,silA)                                       \
  491.  initfstr(B,A[0],(filA),(silA)-1),c2fstrv(A[0],A[0],(silA),(sA));
  492. #else
  493. #define AATRINGV( M,I,A,B, sA,filA,silA)                                       \
  494.  (B.s=malloc((sA)-(filA)),B.fs=c2fstrv(A[0],B.s,(B.flen=(silA)-1)+1,(sA)));
  495. #define APATRINGV(M,I,A,B, sA,filA,silA)                                       \
  496.  B.fs=c2fstrv(A[0],A[0],(B.flen=(silA)-1)+1,B.sizeofA=(sA));
  497. #endif
  498. #define ASTRINGV( M,I,A,B)                                                     \
  499.   AATRINGV( M,I,A,B,sizeof(A),firstindexlength(A),secondindexlength(A)) 
  500. #define APSTRINGV(M,I,A,B)                                                     \
  501.  APATRINGV( M,I,A,B,sizeof(A),firstindexlength(A),secondindexlength(A)) 
  502. #define AZTRINGV( M,I,A,B) AATRINGV( M,I,A,B,                                  \
  503.                     (M/**/_ELEMS_/**/I)*(( M/**/_ELEMLEN_/**/I)+1),            \
  504.                               (M/**/_ELEMS_/**/I),(M/**/_ELEMLEN_/**/I)+1) 
  505. #define APZTRINGV(M,I,A,B) APATRINGV( M,I,A,B,                                 \
  506.                     (M/**/_ELEMS_/**/I)*(( M/**/_ELEMLEN_/**/I)+1),            \
  507.                               (M/**/_ELEMS_/**/I),(M/**/_ELEMLEN_/**/I)+1) 
  508.  
  509. #define AAPPBYTE(   A,B) &A
  510. #define AAPPDOUBLE( A,B) &A
  511. #define AAPPFLOAT(  A,B) PPFLOATVV &A
  512. #define AAPPINT(    A,B) &A
  513. #define AAPPLOGICAL(A,B) B= &A         /* B used to keep a common W table. */
  514. #define AAPPLONG(   A,B) &A
  515. #define AAPPSHORT(  A,B) &A
  516.  
  517. #define AACF(TN,AI,I,C) _SEP_(TN,C,COMMA) _INT(3,AA,TN,AI,B/**/I)
  518. #define AAINT(     T,A,B) &B
  519. #define AAINTV(    T,A,B)  B
  520. #define AAINTVV(   T,A,B)  B
  521. #define AAPINT(    T,A,B) AAP/**/T(A,B)
  522. #define AAPVOID(   T,A,B) (void *) A
  523. #define AASTRING(  T,A,B) CCSTRING(T,A,B)
  524. #define AAPSTRING( T,A,B) CCPSTRING(T,A,B)
  525. #ifdef vmsFortran
  526. #define AASTRINGV( T,A,B) &B
  527. #else
  528. #ifdef CRAYFortran
  529. #define AASTRINGV( T,A,B) _cptofcd(B.fs,B.flen)
  530. #else
  531. #define AASTRINGV( T,A,B) B.fs
  532. #endif
  533. #endif
  534. #define AAPSTRINGV      AASTRINGV
  535. #define AAZTRINGV       AASTRINGV
  536. #define AAPZTRINGV      AASTRINGV
  537.  
  538. #if defined(vmsFortran) || defined(CRAYFortran)
  539. #define JCF(TN,I)
  540. #else
  541. #define JCF(TN,I)    STR_/**/TN(1,J,B/**/I, 0,0,0)
  542. #define JLOGICAL( B)
  543. #define JPLOGICAL(B)
  544. #define JSTRING(  B) ,B.flen
  545. #define JPSTRING( B) ,B
  546. #define JSTRINGV     JSTRING
  547. #define JPSTRINGV    JSTRING
  548. #define JZTRINGV     JSTRING
  549. #define JPZTRINGV    JSTRING
  550. #endif
  551.  
  552. #define WCF(TN,AN,I)   STR_/**/TN(2,W,AN,B/**/I, 0,0)
  553. #define WLOGICAL( A,B)
  554. #define WPLOGICAL(A,B) *B=F2CLOGICAL(*B);
  555. #define WSTRING(  A,B) (A[B.clen]!='\0'?A[B.clen]='\0':0); /* A?="constnt"*/
  556. #define WPSTRING( A,B) kill_trailing(A,' ');
  557. #ifdef vmsFortran
  558. #define WSTRINGV( A,B) free(B.dsc$a_pointer);
  559. #define WPSTRINGV(A,B)                                                         \
  560.   vkill_trailing(f2cstrv((char*)A, (char*)A,                                   \
  561.                            B.dsc$w_length+1, B.dsc$l_arsize+B.dsc$l_m[0]),     \
  562.                    B.dsc$w_length+1, B.dsc$l_arsize+B.dsc$l_m[0], ' ');
  563. #else
  564. #define WSTRINGV( A,B) free(B.s);
  565. #define WPSTRINGV(A,B) vkill_trailing(                                         \
  566.          f2cstrv((char*)A,(char*)A,B.flen+1,B.sizeofA), B.flen+1,B.sizeofA,' ');
  567. #endif
  568. #define WZTRINGV           WSTRINGV
  569. #define WPZTRINGV          WPSTRINGV
  570.  
  571. #define   nCF(TN,  C)  _SEP_(TN,C,COMMA) _INT(1,N,TN,0,0)
  572. #define   NCF(TN,I,C)  _SEP_(TN,C,COMMA) _INT(1,N,TN,0,0) _SEP_(TN,1,I)
  573. #define  NNCF          UUCF
  574. #define NNNCF(TN,I,C)  _SEP_(TN,C,COLON) _INT(1,N,TN,0,0) _SEP_(TN,1,I)
  575. #define NINT(     T) typeP/**/T/**/VV *
  576. #define NINTV(    T) typeP/**/T/**/V  *
  577. #define NINTVV(   T) typeP/**/T       *
  578. #define NPINT(    T)  type/**/T/**/VV *
  579. #define NPVOID(   T) void *
  580. #ifdef vmsFortran
  581. #define NSTRING(  T) fstring *
  582. #define NSTRINGV( T) fstringvector *
  583. #else
  584. #ifdef CRAYFortran
  585. #define NSTRING(  T) _fcd
  586. #define NSTRINGV( T) _fcd
  587. #else
  588. #define NSTRING(  T) char *
  589. #define NSTRINGV( T) char *
  590. #endif
  591. #endif
  592. #define NPSTRING( T) NSTRING(T)   /* CRAY insists on arg.'s here. */
  593. #define NPSTRINGV(T) NSTRINGV(T)
  594. #define NZTRINGV( T) NSTRINGV(T)
  595. #define NPZTRINGV(T) NPSTRINGV(T)
  596.  
  597. /* Note: To avoid compiler warnings, null #define PROTOCCALLSFSUB14/20 after 
  598.    #include-ing cfortran.h if calling the FORTRAN wrapper within the same 
  599.    source code where the wrapper is created. */
  600. #ifndef __CF__KnR
  601. #define PROTOCCALLSFSUB0(UN,LN)          extern void CFC_(UN,LN)();
  602. #define PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE)     \
  603.  extern void CFC_(UN,LN)(nCF(T1,0) nCF(T2,1) nCF(T3,1) nCF(T4,1) nCF(T5,1)     \
  604.      nCF(T6,1) nCF(T7,1) nCF(T8,1) nCF(T9,1) nCF(TA,1) nCF(TB,1) nCF(TC,1)     \
  605.      nCF(TD,1) nCF(TE,1) ,...);
  606. #define PROTOCCALLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK)\
  607.  extern void CFC_(UN,LN)(nCF(T1,0) nCF(T2,1) nCF(T3,1) nCF(T4,1) nCF(T5,1)     \
  608.      nCF(T6,1) nCF(T7,1) nCF(T8,1) nCF(T9,1) nCF(TA,1) nCF(TB,1) nCF(TC,1)     \
  609.      nCF(TD,1) nCF(TE,1) nCF(TF,1) nCF(TG,1) nCF(TH,1) nCF(TI,1) nCF(TJ,1) nCF(TK,1),...);
  610. #else
  611. #define PROTOCCALLSFSUB0( UN,LN)
  612. #define PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE)
  613. #define PROTOCCALLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK)
  614. #endif
  615.  
  616. #if defined(VAXC) && defined(vms)        /* Have avoid %CC-I-PARAMNOTUSED. */
  617. #pragma standard
  618. #endif
  619.  
  620. /* do{...}while(FALSE) allows if(a==b) FORT(); else BORT(); */
  621.  
  622. #define CCALLSFSUB0(UN,LN) \
  623.  do{PROTOCCALLSFSUB0(UN,LN) CFC_(UN,LN)();}while(FALSE)
  624.  
  625. #define CCALLSFSUB1( UN,LN,T1,                        A1)         \
  626.         CCALLSFSUB5 (UN,LN,T1,CF_0,CF_0,CF_0,CF_0,A1,0,0,0,0)
  627. #define CCALLSFSUB2( UN,LN,T1,T2,                     A1,A2)      \
  628.         CCALLSFSUB5 (UN,LN,T1,T2,CF_0,CF_0,CF_0,A1,A2,0,0,0)
  629. #define CCALLSFSUB3( UN,LN,T1,T2,T3,                  A1,A2,A3)   \
  630.         CCALLSFSUB5 (UN,LN,T1,T2,T3,CF_0,CF_0,A1,A2,A3,0,0)
  631. #define CCALLSFSUB4( UN,LN,T1,T2,T3,T4,               A1,A2,A3,A4)\
  632.         CCALLSFSUB5 (UN,LN,T1,T2,T3,T4,CF_0,A1,A2,A3,A4,0)
  633. #define CCALLSFSUB5( UN,LN,T1,T2,T3,T4,T5,            A1,A2,A3,A4,A5)          \
  634.         CCALLSFSUB10(UN,LN,T1,T2,T3,T4,T5,CF_0,CF_0,CF_0,CF_0,CF_0,A1,A2,A3,A4,A5,0,0,0,0,0)
  635. #define CCALLSFSUB6( UN,LN,T1,T2,T3,T4,T5,T6,         A1,A2,A3,A4,A5,A6)       \
  636.         CCALLSFSUB10(UN,LN,T1,T2,T3,T4,T5,T6,CF_0,CF_0,CF_0,CF_0,A1,A2,A3,A4,A5,A6,0,0,0,0)
  637. #define CCALLSFSUB7( UN,LN,T1,T2,T3,T4,T5,T6,T7,      A1,A2,A3,A4,A5,A6,A7)    \
  638.         CCALLSFSUB10(UN,LN,T1,T2,T3,T4,T5,T6,T7,CF_0,CF_0,CF_0,A1,A2,A3,A4,A5,A6,A7,0,0,0)
  639. #define CCALLSFSUB8( UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,   A1,A2,A3,A4,A5,A6,A7,A8) \
  640.         CCALLSFSUB10(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,CF_0,CF_0,A1,A2,A3,A4,A5,A6,A7,A8,0,0)
  641. #define CCALLSFSUB9( UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,A1,A2,A3,A4,A5,A6,A7,A8,A9)\
  642.         CCALLSFSUB10(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,CF_0,A1,A2,A3,A4,A5,A6,A7,A8,A9,0)
  643. #define CCALLSFSUB10(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA)\
  644.         CCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,CF_0,CF_0,CF_0,CF_0,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,0,0,0,0)
  645. #define CCALLSFSUB11(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB)\
  646.         CCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,CF_0,CF_0,CF_0,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,0,0,0)
  647. #define CCALLSFSUB12(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC)\
  648.         CCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,CF_0,CF_0,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,0,0)
  649. #define CCALLSFSUB13(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD)\
  650.         CCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,CF_0,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,0)
  651.  
  652. #define CCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE)\
  653. do{VVCF(T1,A1,B1) VVCF(T2,A2,B2) VVCF(T3,A3,B3) VVCF(T4,A4,B4) VVCF(T5,A5,B5)  \
  654.    VVCF(T6,A6,B6) VVCF(T7,A7,B7) VVCF(T8,A8,B8) VVCF(T9,A9,B9) VVCF(TA,AA,BA)  \
  655.    VVCF(TB,AB,BB) VVCF(TC,AC,BC) VVCF(TD,AD,BD) VVCF(TE,AE,BE)                 \
  656.    PROTOCCALLSFSUB14(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE)          \
  657.    ACF(LN,T1,A1,1) ACF(LN,T2,A2,2) ACF(LN,T3,A3,3)                             \
  658.    ACF(LN,T4,A4,4) ACF(LN,T5,A5,5) ACF(LN,T6,A6,6) ACF(LN,T7,A7,7)             \
  659.    ACF(LN,T8,A8,8) ACF(LN,T9,A9,9) ACF(LN,TA,AA,A) ACF(LN,TB,AB,B)             \
  660.    ACF(LN,TC,AC,C) ACF(LN,TD,AD,D) ACF(LN,TE,AE,E)                             \
  661.    CFC_(UN,LN)(AACF(T1,A1,1,0) AACF(T2,A2,2,1) AACF(T3,A3,3,1)                 \
  662.                AACF(T4,A4,4,1) AACF(T5,A5,5,1) AACF(T6,A6,6,1) AACF(T7,A7,7,1) \
  663.                AACF(T8,A8,8,1) AACF(T9,A9,9,1) AACF(TA,AA,A,1) AACF(TB,AB,B,1) \
  664.                AACF(TC,AC,C,1) AACF(TD,AD,D,1) AACF(TE,AE,E,1)                 \
  665.       JCF(T1,1) JCF(T2,2) JCF(T3,3) JCF(T4,4) JCF(T5,5) JCF(T6,6) JCF(T7,7)    \
  666.       JCF(T8,8) JCF(T9,9) JCF(TA,A) JCF(TB,B) JCF(TC,C) JCF(TD,D) JCF(TE,E)  );\
  667.    WCF(T1,A1,1) WCF(T2,A2,2) WCF(T3,A3,3) WCF(T4,A4,4) WCF(T5,A5,5)            \
  668.    WCF(T6,A6,6) WCF(T7,A7,7) WCF(T8,A8,8) WCF(T9,A9,9) WCF(TA,AA,A)            \
  669.    WCF(TB,AB,B) WCF(TC,AC,C) WCF(TD,AD,D) WCF(TE,AE,E)             }while(FALSE)
  670.  
  671. /* Apollo 6.7, CRAY, Sun, VAX/Ultrix vcc/cc and HP can't hack more than 31 arg's */
  672. #if !(defined(VAXUltrix)&&!defined(__GNUC__)) && !defined(__CF__APOLLO67) && !defined(sun) && !defined(__hp9000s300) && !defined(_CRAY)
  673. #define CCALLSFSUB15(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF)\
  674.         CCALLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,CF_0,CF_0,CF_0,CF_0,CF_0,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF,0,0,0,0,0)
  675. #define CCALLSFSUB16(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF,AG)\
  676.         CCALLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,CF_0,CF_0,CF_0,CF_0,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF,AG,0,0,0,0)
  677. #define CCALLSFSUB17(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF,AG,AH)\
  678.         CCALLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,CF_0,CF_0,CF_0,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF,AG,AH,0,0,0)
  679. #define CCALLSFSUB18(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF,AG,AH,AI)\
  680.         CCALLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,CF_0,CF_0,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF,AG,AH,AI,0,0)
  681. #define CCALLSFSUB19(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ)\
  682.         CCALLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,CF_0,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,0)
  683.  
  684. /* PROTOCCALLSFSUB20 is commented out, because it chokes the VAX VMS compiler.
  685.    It isn't required since we so far only pass pointers and integers to 
  686.    FORTRAN routines and these arg.'s aren't promoted to anything else.        */
  687.  
  688. #define CCALLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH, \
  689.         TI,TJ,TK, A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK) \
  690. do{VVCF(T1,A1,B1) VVCF(T2,A2,B2) VVCF(T3,A3,B3) VVCF(T4,A4,B4) VVCF(T5,A5,B5)  \
  691.    VVCF(T6,A6,B6) VVCF(T7,A7,B7) VVCF(T8,A8,B8) VVCF(T9,A9,B9) VVCF(TA,AA,BA)  \
  692.    VVCF(TB,AB,BB) VVCF(TC,AC,BC) VVCF(TD,AD,BD) VVCF(TE,AE,BE) VVCF(TF,AF,BF)  \
  693.    VVCF(TG,AG,BG) VVCF(TH,AH,BH) VVCF(TI,AI,BI) VVCF(TJ,AJ,BJ) VVCF(TK,AK,BK)  \
  694. /*   PROTOCCALLSFSUB20(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK)*/\
  695.    ACF(LN,T1,A1,1) ACF(LN,T2,A2,2) ACF(LN,T3,A3,3) ACF(LN,T4,A4,4)             \
  696.    ACF(LN,T5,A5,5) ACF(LN,T6,A6,6) ACF(LN,T7,A7,7) ACF(LN,T8,A8,8)             \
  697.    ACF(LN,T9,A9,9) ACF(LN,TA,AA,A) ACF(LN,TB,AB,B) ACF(LN,TC,AC,C)             \
  698.    ACF(LN,TD,AD,D) ACF(LN,TE,AE,E) ACF(LN,TF,AF,F) ACF(LN,TG,AG,G)             \
  699.    ACF(LN,TH,AH,H) ACF(LN,TI,AI,I) ACF(LN,TJ,AJ,J) ACF(LN,TK,AK,K)             \
  700.    CFC_(UN,LN)(AACF(T1,A1,1,0) AACF(T2,A2,2,1) AACF(T3,A3,3,1) AACF(T4,A4,4,1) \
  701.                AACF(T5,A5,5,1) AACF(T6,A6,6,1) AACF(T7,A7,7,1) AACF(T8,A8,8,1) \
  702.                AACF(T9,A9,9,1) AACF(TA,AA,A,1) AACF(TB,AB,B,1) AACF(TC,AC,C,1) \
  703.                AACF(TD,AD,D,1) AACF(TE,AE,E,1) AACF(TF,AF,F,1) AACF(TG,AG,G,1) \
  704.                AACF(TH,AH,H,1) AACF(TI,AI,I,1) AACF(TJ,AJ,J,1) AACF(TK,AK,K,1) \
  705.       JCF(T1,1) JCF(T2,2) JCF(T3,3) JCF(T4,4) JCF(T5,5) JCF(T6,6) JCF(T7,7)    \
  706.       JCF(T8,8) JCF(T9,9) JCF(TA,A) JCF(TB,B) JCF(TC,C) JCF(TD,D) JCF(TE,E)    \
  707.       JCF(TF,F) JCF(TG,G) JCF(TH,H) JCF(TI,I) JCF(TJ,J) JCF(TK,K)          );  \
  708.  WCF(T1,A1,1) WCF(T2,A2,2) WCF(T3,A3,3) WCF(T4,A4,4) WCF(T5,A5,5) WCF(T6,A6,6) \
  709.  WCF(T7,A7,7) WCF(T8,A8,8) WCF(T9,A9,9) WCF(TA,AA,A) WCF(TB,AB,B) WCF(TC,AC,C) \
  710.  WCF(TD,AD,D) WCF(TE,AE,E) WCF(TF,AF,F) WCF(TG,AG,G) WCF(TH,AH,H) WCF(TI,AI,I) \
  711.  WCF(TJ,AJ,J) WCF(TK,AK,K) }while(FALSE)
  712. #endif         /* Apollo 6.7, CRAY, Sun and HP can't hack more than 31 arg.'s */
  713.  
  714. /*-------------------------------------------------------------------------*/
  715.  
  716. /*               UTILITIES FOR C TO CALL FORTRAN FUNCTIONS                 */
  717.  
  718. /*N.B. PROTOCCALLSFFUNn(..) generates code, whether or not the FORTRAN
  719.   function is called. Therefore, especially for creator's of C header files
  720.   for large FORTRAN libraries which include many functions, to reduce
  721.   compile time and object code size, it may be desirable to create
  722.   preprocessor directives to allow users to create code for only those
  723.   functions which they use.                                                */
  724.  
  725. /* The following defines the maximum length string that a function can return.
  726.    Of course it may be undefine-d and re-define-d before individual
  727.    PROTOCCALLSFFUNn(..) as required. It would also be nice to have this derived
  728.    from the individual machines' limits.                                      */
  729. #define MAX_LEN_FORTRAN_FUNCTION_STRING 0x4FE
  730.  
  731. /* The following defines a character used by CFORTRAN.H to flag the end of a
  732.    string coming out of a FORTRAN routine.                                 */
  733. #define CFORTRAN_NON_CHAR 0x7F
  734.  
  735. #if defined(VAXC) && defined(vms)        /* To avoid %CC-I-PARAMNOTUSED. */
  736. #pragma nostandard
  737. #endif
  738.  
  739. #define _SEP_(TN,C,COMMA) __SEP_/**/C(TN,COMMA)
  740. #define __SEP_0(TN,COMMA)  
  741. #define __SEP_1(TN,COMMA)  _INT(2,SEP_,TN,COMMA,0)
  742. #define SEP_INT(     T,B) A/**/B
  743. #define SEP_INTV     SEP_INT
  744. #define SEP_INTVV    SEP_INT
  745. #define SEP_PINT     SEP_INT
  746. #define SEP_PVOID    SEP_INT
  747. #define SEP_SIMPLE   SEP_INT
  748. #define SEP_VOID     SEP_INT      /* Need for FORTRAN calls to C subroutines. */
  749. #define SEP_STRING   SEP_INT
  750. #define SEP_STRINGV  SEP_INT
  751. #define SEP_PSTRING  SEP_INT
  752. #define SEP_PSTRINGV SEP_INT
  753. #define SEP_ZTRINGV  SEP_INT
  754. #define SEP_PZTRINGV SEP_INT
  755.                          
  756. #if defined(SIGNED_BYTE) || !defined(UNSIGNED_BYTE)
  757. #if defined(VAXC) && defined(vms)
  758. #define INTEGER_BYTE            char        /* VAXC barfs on 'signed char' */
  759. #else
  760. #define INTEGER_BYTE     signed char        /* default */
  761. #endif
  762. #else
  763. #define INTEGER_BYTE   unsigned char
  764. #endif
  765. #define typePBYTEVV    INTEGER_BYTE
  766. #define typePDOUBLEVV  DOUBLE_PRECISION 
  767. #define typePFLOATVV   float
  768. #define typePINTVV     int
  769. #define typePLOGICALVV int
  770. #define typePLONGVV    long
  771. #define typePSHORTVV   short
  772.  
  773. #define CFARGS0(A,T,W,X,Y,Z) A/**/T
  774. #define CFARGS1(A,T,W,X,Y,Z) A/**/T(W)
  775. #define CFARGS2(A,T,W,X,Y,Z) A/**/T(W,X)
  776. #define CFARGS3(A,T,W,X,Y,Z) A/**/T(W,X,Y)
  777. #define CFARGS4(A,T,W,X,Y,Z) A/**/T(W,X,Y,Z)
  778.  
  779. #define _INT(N,T,I,Y,Z) INT_/**/I(N,T,I,Y,Z)
  780. #define INT_BYTE     INT_DOUBLE
  781. #define INT_DOUBLE(  N,A,B,Y,Z) CFARGS/**/N(A,INT,B,Y,Z,0)
  782. #define INT_FLOAT    INT_DOUBLE
  783. #define INT_INT      INT_DOUBLE
  784. #define INT_LOGICAL  INT_DOUBLE
  785. #define INT_LONG     INT_DOUBLE
  786. #define INT_SHORT    INT_DOUBLE
  787. #define INT_BYTEV    INT_DOUBLEV
  788. #define INT_DOUBLEV( N,A,B,Y,Z) CFARGS/**/N(A,INTV,B,Y,Z,0)
  789. #define INT_FLOATV   INT_DOUBLEV
  790. #define INT_INTV     INT_DOUBLEV
  791. #define INT_LOGICALV INT_DOUBLEV
  792. #define INT_LONGV    INT_DOUBLEV
  793. #define INT_SHORTV   INT_DOUBLEV
  794. #define INT_BYTEVV   INT_DOUBLEVV
  795. #define INT_DOUBLEVV(N,A,B,Y,Z) CFARGS/**/N(A,INTVV,B,Y,Z,0)
  796. #define INT_FLOATVV  INT_DOUBLEVV
  797. #define INT_INTVV    INT_DOUBLEVV
  798. #define INT_LOGICALVV INT_DOUBLEVV
  799. #define INT_LONGVV   INT_DOUBLEVV
  800. #define INT_SHORTVV  INT_DOUBLEVV
  801. #define INT_PBYTE    INT_PDOUBLE
  802. #define INT_PDOUBLE( N,A,B,Y,Z) CFARGS/**/N(A,PINT,B,Y,Z,0)
  803. #define INT_PFLOAT   INT_PDOUBLE
  804. #define INT_PINT     INT_PDOUBLE
  805. #define INT_PLOGICAL INT_PDOUBLE
  806. #define INT_PLONG    INT_PDOUBLE
  807. #define INT_PSHORT   INT_PDOUBLE
  808. #define INT_PVOID(   N,A,B,Y,Z) CFARGS/**/N(A,B,B,Y,Z,0)
  809. /*CRAY coughs on the first, i.e. the usual trouble of not being able to
  810.   define macros to macros with arguments. */
  811. /*#define INT_SIMPLE   INT_PVOID*/
  812. #define INT_SIMPLE(  N,A,B,Y,Z)   INT_PVOID(N,A,B,Y,Z)
  813. #define INT_VOID     INT_PVOID
  814. #define INT_STRING   INT_PVOID
  815. #define INT_STRINGV  INT_PVOID
  816. #define INT_PSTRING  INT_PVOID
  817. #define INT_PSTRINGV INT_PVOID
  818. #define INT_ZTRINGV  INT_PVOID
  819. #define INT_PZTRINGV INT_PVOID
  820. #define INT_CF_0(    N,A,B,Y,Z)
  821.                          
  822. #define   UCF(TN,I,C)  _SEP_(TN,C,COMMA) _INT(2,U,TN,A/**/I,0)
  823. #define  UUCF(TN,I,C)  _SEP_(TN,C,COMMA) _SEP_(TN,1,I) 
  824. #define UUUCF(TN,I,C)  _SEP_(TN,C,COLON) _INT(2,U,TN,A/**/I,0)
  825. #define UINT(     T,A) typeP/**/T/**/VV  A
  826. #define UINTV(    T,A) typeP/**/T/**/V  *A
  827. #define UINTVV(   T,A) typeP/**/T       *A
  828. #define UPINT(    T,A)  type/**/T/**/VV *A
  829. #define UPVOID(   T,A) void *A 
  830. #define UVOID(    T,A) void *A          /*Needed for FORTRAN/C subroutines. */
  831. #define USTRING(  T,A) char *A 
  832. #define USTRINGV( T,A) char *A
  833. #define UPSTRING( T,A) char *A
  834. #define UPSTRINGV(T,A) char *A
  835. #define UZTRINGV( T,A) char *A
  836. #define UPZTRINGV(T,A) char *A
  837.  
  838. /* Only Sun breaks U into U and PU. */
  839. #define PUBYTE(      A) INTEGER_BYTE     A
  840. #define PUDOUBLE(    A) DOUBLE_PRECISION A
  841. #ifndef sunFortran
  842. #define PUFLOAT(     A) float   A
  843. #else
  844. #define PUFLOAT(     A) FLOATFUNCTIONTYPE   A
  845. #endif
  846. #define PUINT(       A) int     A
  847. #define PULOGICAL(   A) int     A
  848. #define PULONG(      A) long    A
  849. #define PUSHORT(     A) short   A
  850. #define PUSTRING(    A) char   *A 
  851. #define PUVOID(      A) void    A
  852.  
  853. #define EBYTE          INTEGER_BYTE     A0;
  854. #define EDOUBLE        DOUBLE_PRECISION A0;
  855. #ifndef sunFortran
  856. #define EFLOAT         float  A0;
  857. #else
  858. #define EFLOAT         float AA0;   FLOATFUNCTIONTYPE A0;
  859. #endif
  860. #define EINT           int    A0;
  861. #define ELOGICAL       int    A0;
  862. #define ELONG          long   A0;
  863. #define ESHORT         short  A0;
  864. #define EVOID
  865. #ifdef vmsFortran
  866. #define ESTRING        static char AA0[MAX_LEN_FORTRAN_FUNCTION_STRING+1];     \
  867.                        static fstring A0 =                                     \
  868.              {MAX_LEN_FORTRAN_FUNCTION_STRING,DSC$K_DTYPE_T,DSC$K_CLASS_S,AA0};\
  869.                memset(AA0, CFORTRAN_NON_CHAR, MAX_LEN_FORTRAN_FUNCTION_STRING);\
  870.                                     *(AA0+MAX_LEN_FORTRAN_FUNCTION_STRING)='\0';
  871. #else
  872. #ifdef CRAYFortran
  873. #define ESTRING        static char AA0[MAX_LEN_FORTRAN_FUNCTION_STRING+1];     \
  874.                    static _fcd A0; *(AA0+MAX_LEN_FORTRAN_FUNCTION_STRING)='\0';\
  875.                 memset(AA0,CFORTRAN_NON_CHAR, MAX_LEN_FORTRAN_FUNCTION_STRING);\
  876.                             A0 = _cptofcd(AA0,MAX_LEN_FORTRAN_FUNCTION_STRING);
  877. #else
  878. #define ESTRING        static char A0[MAX_LEN_FORTRAN_FUNCTION_STRING+1];      \
  879.                        memset(A0, CFORTRAN_NON_CHAR,                           \
  880.                               MAX_LEN_FORTRAN_FUNCTION_STRING);                \
  881.                        *(A0+MAX_LEN_FORTRAN_FUNCTION_STRING)='\0';
  882. #endif
  883. #endif
  884. /* ESTRING must use static char. array which is guaranteed to exist after
  885.    function returns.                                                     */
  886.  
  887. /* N.B.i) The diff. for 0 (Zero) and >=1 arguments.
  888.        ii)That the following create an unmatched bracket, i.e. '(', which
  889.           must of course be matched in the call.
  890.        iii)Commas must be handled very carefully                         */
  891. #define GZINT(    T,UN,LN) A0=CFC_(UN,LN)(
  892. #define GZVOID(   T,UN,LN)    CFC_(UN,LN)(
  893. #ifdef vmsFortran
  894. #define GZSTRING( T,UN,LN)    CFC_(UN,LN)(&A0
  895. #else
  896. #ifdef CRAYFortran
  897. #define GZSTRING( T,UN,LN)    CFC_(UN,LN)( A0
  898. #else
  899. #define GZSTRING( T,UN,LN)    CFC_(UN,LN)( A0,MAX_LEN_FORTRAN_FUNCTION_STRING
  900. #endif
  901. #endif
  902.  
  903. #define GINT               GZINT
  904. #define GVOID              GZVOID
  905. #define GSTRING(  T,UN,LN) GZSTRING(T,UN,LN),
  906.  
  907. #define PPBYTEVV
  908. #define PPINTVV     /* These complement PPFLOATVV. */
  909. #define PPDOUBLEVV
  910. #define PPLOGICALVV
  911. #define PPLONGVV
  912. #define PPSHORTVV
  913.  
  914. #define BCF(TN,AN,C)   _SEP_(TN,C,COMMA) _INT(2,B,TN,AN,0)
  915. #define BINT(     T,A) (typeP/**/T/**/VV) A
  916. #define BINTV(    T,A)           A
  917. #define BINTVV(   T,A)          (A)[0]
  918. #define BPINT(    T,A) P/**/T/**/VV  &A
  919. #define BSTRING(  T,A) (char *)  A
  920. #define BSTRINGV( T,A) (char *)  A
  921. #define BPSTRING( T,A) (char *)  A
  922. #define BPSTRINGV(T,A) (char *)  A
  923. #define BPVOID(   T,A) (void *)  A
  924. #define BZTRINGV( T,A) (char *)  A
  925. #define BPZTRINGV(T,A) (char *)  A
  926.                                                                   
  927. #define ZCF(TN,N,AN)   _INT(3,Z,TN,N,AN)
  928. #define ZINT(     T,I,A) (__cfztringv[I]=(int)A),
  929. #define ZPINT            ZINT
  930. #define ZINTV(    T,I,A)
  931. #define ZINTVV(   T,I,A)
  932. #define ZSTRING(  T,I,A)
  933. #define ZSTRINGV( T,I,A)
  934. #define ZPSTRING( T,I,A)
  935. #define ZPSTRINGV(T,I,A)
  936. #define ZPVOID(   T,I,A)
  937. #define ZSIMPLE(  T,I,A)
  938. #define ZZTRINGV( T,I,A)
  939. #define ZPZTRINGV(T,I,A)
  940.  
  941. #define SCF(TN,NAME,I,A) STR_/**/TN(3,S,NAME,I,A,0)
  942. #define SLOGICAL( M,I,A)
  943. #define SPLOGICAL(M,I,A)
  944. #define SSTRING(  M,I,A) ,sizeof(A)
  945. #define SSTRINGV( M,I,A) ,( (unsigned)0xFFFF*firstindexlength(A)               \
  946.                              +secondindexlength(A))
  947. #define SPSTRING( M,I,A) ,sizeof(A)
  948. #define SPSTRINGV          SSTRINGV
  949. #define SZTRINGV( M,I,A) ,( (unsigned)0xFFFF*M/**/_ELEMS_/**/I                 \
  950.                              +M/**/_ELEMLEN_/**/I+1)
  951. #define SPZTRINGV        SZTRINGV
  952.  
  953. #define   HCF(TN,I)      STR_/**/TN(3,H,COMMA, H,C/**/I,0)
  954. #define  HHCF(TN,I)      STR_/**/TN(3,H,COMMA,HH,C/**/I,0)
  955. #define HHHCF(TN,I)      STR_/**/TN(3,H,COLON, H,C/**/I,0)
  956. #define  H_CF_SPECIAL    unsigned
  957. #define HH_CF_SPECIAL
  958. #define HLOGICAL( S,U,B)
  959. #define HPLOGICAL(S,U,B)
  960. #define HSTRING(  S,U,B) A/**/S U/**/_CF_SPECIAL B
  961. #define HSTRINGV         HSTRING    
  962. #define HPSTRING         HSTRING
  963. #define HPSTRINGV        HSTRING
  964. #define HZTRINGV         HSTRING
  965. #define HPZTRINGV        HSTRING
  966.  
  967. #define STR_BYTE(    N,T,A,B,C,D)
  968. #define STR_DOUBLE(  N,T,A,B,C,D)            /* Can't add spaces inside       */
  969. #define STR_FLOAT(   N,T,A,B,C,D)            /* expansion since it screws up  */
  970. #define STR_INT(     N,T,A,B,C,D)            /* macro catenation kludge.      */
  971. #define STR_LOGICAL( N,T,A,B,C,D) CFARGS/**/N(T,LOGICAL,A,B,C,D)
  972. #define STR_LONG(    N,T,A,B,C,D)
  973. #define STR_SHORT(   N,T,A,B,C,D)
  974. #define STR_BYTEV(   N,T,A,B,C,D)
  975. #define STR_DOUBLEV( N,T,A,B,C,D)
  976. #define STR_FLOATV(  N,T,A,B,C,D)
  977. #define STR_INTV(    N,T,A,B,C,D)
  978. #define STR_LOGICALV(N,T,A,B,C,D)
  979. #define STR_LONGV(   N,T,A,B,C,D)
  980. #define STR_SHORTV(  N,T,A,B,C,D)
  981. #define STR_BYTEVV(  N,T,A,B,C,D)
  982. #define STR_DOUBLEVV(N,T,A,B,C,D)
  983. #define STR_FLOATVV( N,T,A,B,C,D)
  984. #define STR_INTVV(   N,T,A,B,C,D)
  985. #define STR_LOGICALVV(N,T,A,B,C,D)
  986. #define STR_LONGVV(  N,T,A,B,C,D)
  987. #define STR_SHORTVV( N,T,A,B,C,D)
  988. #define STR_PBYTE(   N,T,A,B,C,D)
  989. #define STR_PDOUBLE( N,T,A,B,C,D)
  990. #define STR_PFLOAT(  N,T,A,B,C,D)
  991. #define STR_PINT(    N,T,A,B,C,D)
  992. #define STR_PLOGICAL(N,T,A,B,C,D) CFARGS/**/N(T,PLOGICAL,A,B,C,D)
  993. #define STR_PLONG(   N,T,A,B,C,D)
  994. #define STR_PSHORT(  N,T,A,B,C,D)
  995. #define STR_STRING(  N,T,A,B,C,D) CFARGS/**/N(T,STRING,A,B,C,D)
  996. #define STR_PSTRING( N,T,A,B,C,D) CFARGS/**/N(T,PSTRING,A,B,C,D)
  997. #define STR_STRINGV( N,T,A,B,C,D) CFARGS/**/N(T,STRINGV,A,B,C,D)
  998. #define STR_PSTRINGV(N,T,A,B,C,D) CFARGS/**/N(T,PSTRINGV,A,B,C,D)
  999. #define STR_PVOID(   N,T,A,B,C,D)
  1000. #define STR_SIMPLE(  N,T,A,B,C,D)
  1001. #define STR_ZTRINGV( N,T,A,B,C,D) CFARGS/**/N(T,ZTRINGV,A,B,C,D)
  1002. #define STR_PZTRINGV(N,T,A,B,C,D) CFARGS/**/N(T,PZTRINGV,A,B,C,D)
  1003. #define STR_CF_0(    N,T,A,B,C,D)               
  1004.  
  1005. /* See ACF table comments, which explain why CCF was split into two. */
  1006. #define CCF(TN,I)          STR_/**/TN(3,C,A/**/I,B/**/I,C/**/I,0)
  1007. #define CLOGICAL( A,B,C)  A=C2FLOGICAL( A);
  1008. #define CPLOGICAL(A,B,C) *A=C2FLOGICAL(*A);
  1009. #ifdef vmsFortran
  1010. #define CSTRING(  A,B,C) (B.clen=strlen(A),B.f.dsc$a_pointer=A,                \
  1011.                     C==sizeof(char*)||C==B.clen+1?B.f.dsc$w_length=B.clen:     \
  1012.           (memset((A)+B.clen,' ',C-B.clen-1),A[B.f.dsc$w_length=C-1]='\0'));
  1013. #define CSTRINGV( A,B,C) (                                                     \
  1014.           initfstr(B, malloc((C/0xFFFF)*(C%0xFFFF-1)), C/0xFFFF, C%0xFFFF-1),  \
  1015.           c2fstrv(A,B.dsc$a_pointer,C%0xFFFF,(C/0xFFFF)*(C%0xFFFF)) );
  1016. #define CPSTRING( A,B,C) (B.dsc$w_length=strlen(A),B.dsc$a_pointer=A,          \
  1017.         C==sizeof(char*)?0:(memset((A)+B.dsc$w_length,' ',C-B.dsc$w_length-1), \
  1018.                              A[B.dsc$w_length=C-1]='\0'));
  1019. #define CPSTRINGV(A,B,C)  (initfstr(B, A, C/0xFFFF, C%0xFFFF-1),               \
  1020.                              c2fstrv(A,A,C%0xFFFF,(C/0xFFFF)*(C%0xFFFF)) );
  1021. #else
  1022. #ifdef CRAYFortran
  1023. #define CSTRING(  A,B,C) (B.clen=strlen(A),                                    \
  1024.                           C==sizeof(char*)||C==B.clen+1?B.flen=B.clen:         \
  1025.                         (memset((A)+B.clen,' ',C-B.clen-1),A[B.flen=C-1]='\0'));
  1026. #define CSTRINGV( A,B,C) (B.s=malloc((C/0xFFFF)*(C%0xFFFF-1)),                 \
  1027.                     c2fstrv(A,B.s,(B.flen=C%0xFFFF-1)+1,(C/0xFFFF)*(C%0xFFFF)));
  1028. #define CPSTRING( A,B,C) (B=strlen(A), C==sizeof(char*)?0:                     \
  1029.                             (memset((A)+B,' ',C-B-1),A[B=C-1]='\0'));
  1030. #define CPSTRINGV(A,B,C) c2fstrv(A,A,(B.flen=C%0xFFFF-1)+1,                    \
  1031.                                    B.sizeofA=(C/0xFFFF)*(C%0xFFFF));
  1032. #else
  1033. #define CSTRING(  A,B,C) (B.clen=strlen(A),                                    \
  1034.                             C==sizeof(char*)||C==B.clen+1?B.flen=B.clen:       \
  1035.                         (memset((A)+B.clen,' ',C-B.clen-1),A[B.flen=C-1]='\0'));
  1036. #define CSTRINGV( A,B,C) (B.s=malloc((C/0xFFFF)*(C%0xFFFF-1)),                 \
  1037.                B.fs=c2fstrv(A,B.s,(B.flen=C%0xFFFF-1)+1,(C/0xFFFF)*(C%0xFFFF)));
  1038. #define CPSTRING( A,B,C) (B=strlen(A), C==sizeof(char*)?0:                     \
  1039.                             (memset((A)+B,' ',C-B-1),A[B=C-1]='\0'));
  1040. #define CPSTRINGV(A,B,C) B.fs=c2fstrv(A,A,(B.flen=C%0xFFFF-1)+1,               \
  1041.                                         B.sizeofA=(C/0xFFFF)*(C%0xFFFF));
  1042. #endif
  1043. #endif
  1044. #define CZTRINGV         CSTRINGV
  1045. #define CPZTRINGV        CPSTRINGV
  1046.  
  1047. #define CCCBYTE(    A,B) &A
  1048. #define CCCDOUBLE(  A,B) &A
  1049. #if !defined(__CF__KnR)
  1050. #define CCCFLOAT(   A,B) &A
  1051.                             /* Although the VAX doesn't, at least the         */
  1052. #else                       /* HP and K&R mips promote float arg.'s of        */
  1053. #define CCCFLOAT(   A,B) &B  /* unprototyped functions to double. So we can't  */
  1054. #endif                      /* use A here to pass the argument to FORTRAN.    */
  1055. #define CCCINT(     A,B) &A
  1056. #define CCCLOGICAL( A,B) &A
  1057. #define CCCLONG(    A,B) &A
  1058. #define CCCSHORT(   A,B) &A
  1059. #define CCCPBYTE(   A,B)  A
  1060. #define CCCPDOUBLE( A,B)  A
  1061. #define CCCPFLOAT(  A,B)  A
  1062. #define CCCPINT(    A,B)  A
  1063. #define CCCPLOGICAL(A,B)  B=A       /* B used to keep a common W table. */
  1064. #define CCCPLONG(   A,B)  A
  1065. #define CCCPSHORT(  A,B)  A
  1066.  
  1067. #define CCCF(TN,I,M)    _SEP_(TN,M,COMMA) _INT(3,CC,TN,A/**/I,B/**/I)
  1068. #define CCINT(     T,A,B) CCC/**/T(A,B) 
  1069. #define CCINTV(    T,A,B)  A
  1070. #define CCINTVV(   T,A,B)  A
  1071. #define CCPINT(    T,A,B) CCC/**/T(A,B) 
  1072. #define CCPVOID(   T,A,B)  A
  1073. #define CCSIMPLE(  T,A,B)  A
  1074. #ifdef vmsFortran
  1075. #define CCSTRING(  T,A,B) &B.f
  1076. #define CCSTRINGV( T,A,B) &B
  1077. #define CCPSTRING( T,A,B) &B
  1078. #define CCPSTRINGV(T,A,B) &B
  1079. #else
  1080. #ifdef CRAYFortran
  1081. #define CCSTRING(  T,A,B) _cptofcd(A,B.flen)
  1082. #define CCSTRINGV( T,A,B) _cptofcd(B.s,B.flen)
  1083. #define CCPSTRING( T,A,B) _cptofcd(A,B)
  1084. #define CCPSTRINGV(T,A,B) _cptofcd(A,B.flen)
  1085. #else
  1086. #define CCSTRING(  T,A,B)  A
  1087. #define CCSTRINGV( T,A,B)  B.fs
  1088. #define CCPSTRING( T,A,B)  A
  1089. #define CCPSTRINGV(T,A,B)  B.fs
  1090. #endif
  1091. #endif
  1092. #define CCZTRINGV       CCSTRINGV
  1093. #define CCPZTRINGV      CCPSTRINGV
  1094.  
  1095. #define XBYTE          return A0;
  1096. #define XDOUBLE        return A0;
  1097. #ifndef sunFortran
  1098. #define XFLOAT         return A0;
  1099. #else
  1100. #define XFLOAT         ASSIGNFLOAT(AA0,A0); return AA0;
  1101. #endif
  1102. #define XINT           return A0;
  1103. #define XLOGICAL       return F2CLOGICAL(A0);
  1104. #define XLONG          return A0;
  1105. #define XSHORT         return A0;
  1106. #define XVOID          return   ;
  1107. #if defined(vmsFortran) || defined(CRAYFortran)
  1108. #define XSTRING        return kill_trailing(                                   \
  1109.                                       kill_trailing(AA0,CFORTRAN_NON_CHAR),' ');
  1110. #else
  1111. #define XSTRING        return kill_trailing(                                   \
  1112.                                       kill_trailing( A0,CFORTRAN_NON_CHAR),' ');
  1113. #endif
  1114.  
  1115. #define CFFUN(NAME) __cf__/**/NAME
  1116.  
  1117. /* Note that we don't use LN here, but we keep it for consistency. */
  1118. #define CCALLSFFUN0(UN,LN) CFFUN(UN)()
  1119.  
  1120. #if defined(VAXC) && defined(vms)        /* Have avoided %CC-I-PARAMNOTUSED. */
  1121. #pragma standard
  1122. #endif
  1123.  
  1124. #define CCALLSFFUN1( UN,LN,T1,                        A1)         \
  1125.         CCALLSFFUN5 (UN,LN,T1,CF_0,CF_0,CF_0,CF_0,A1,0,0,0,0)
  1126. #define CCALLSFFUN2( UN,LN,T1,T2,                     A1,A2)      \
  1127.         CCALLSFFUN5 (UN,LN,T1,T2,CF_0,CF_0,CF_0,A1,A2,0,0,0)
  1128. #define CCALLSFFUN3( UN,LN,T1,T2,T3,                  A1,A2,A3)   \
  1129.         CCALLSFFUN5 (UN,LN,T1,T2,T3,CF_0,CF_0,A1,A2,A3,0,0)
  1130. #define CCALLSFFUN4( UN,LN,T1,T2,T3,T4,               A1,A2,A3,A4)\
  1131.         CCALLSFFUN5 (UN,LN,T1,T2,T3,T4,CF_0,A1,A2,A3,A4,0)
  1132. #define CCALLSFFUN5( UN,LN,T1,T2,T3,T4,T5,            A1,A2,A3,A4,A5)          \
  1133.         CCALLSFFUN10(UN,LN,T1,T2,T3,T4,T5,CF_0,CF_0,CF_0,CF_0,CF_0,A1,A2,A3,A4,A5,0,0,0,0,0)
  1134. #define CCALLSFFUN6( UN,LN,T1,T2,T3,T4,T5,T6,         A1,A2,A3,A4,A5,A6)       \
  1135.         CCALLSFFUN10(UN,LN,T1,T2,T3,T4,T5,T6,CF_0,CF_0,CF_0,CF_0,A1,A2,A3,A4,A5,A6,0,0,0,0)
  1136. #define CCALLSFFUN7( UN,LN,T1,T2,T3,T4,T5,T6,T7,      A1,A2,A3,A4,A5,A6,A7)    \
  1137.         CCALLSFFUN10(UN,LN,T1,T2,T3,T4,T5,T6,T7,CF_0,CF_0,CF_0,A1,A2,A3,A4,A5,A6,A7,0,0,0)
  1138. #define CCALLSFFUN8( UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,   A1,A2,A3,A4,A5,A6,A7,A8) \
  1139.         CCALLSFFUN10(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,CF_0,CF_0,A1,A2,A3,A4,A5,A6,A7,A8,0,0)
  1140. #define CCALLSFFUN9( UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,A1,A2,A3,A4,A5,A6,A7,A8,A9)\
  1141.         CCALLSFFUN10(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,CF_0,A1,A2,A3,A4,A5,A6,A7,A8,A9,0)
  1142.  
  1143. #define CCALLSFFUN10(UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA)\
  1144. (ZCF(T1,1,A1) ZCF(T2,2,A2) ZCF(T3,3,A3) ZCF(T4,4,A4) ZCF(T5,5,A5)              \
  1145.  ZCF(T6,6,A6) ZCF(T7,7,A7) ZCF(T8,8,A8) ZCF(T9,9,A9) ZCF(TA,A,AA)              \
  1146.  (CFFUN(UN)(  BCF(T1,A1,0) BCF(T2,A2,1) BCF(T3,A3,1) BCF(T4,A4,1) BCF(T5,A5,1) \
  1147.               BCF(T6,A6,1) BCF(T7,A7,1) BCF(T8,A8,1) BCF(T9,A9,1) BCF(TA,AA,1) \
  1148.            SCF(T1,LN,1,A1) SCF(T2,LN,2,A2) SCF(T3,LN,3,A3) SCF(T4,LN,4,A4)     \
  1149.            SCF(T5,LN,5,A5) SCF(T6,LN,6,A6) SCF(T7,LN,7,A7) SCF(T8,LN,8,A8)     \
  1150.            SCF(T9,LN,9,A9) SCF(TA,LN,A,AA))))
  1151.  
  1152. /*  N.B. Create a separate function instead of using (call function, function
  1153. value here) because in order to create the variables needed for the input
  1154. arg.'s which may be const.'s one has to do the creation within {}, but these
  1155. can never be placed within ()'s. Therefore one must create wrapper functions.
  1156. gcc, on the other hand may be able to avoid the wrapper functions. */
  1157.  
  1158. /* Prototypes are needed to correctly handle the value returned correctly. N.B.
  1159. Can only have prototype arg.'s with difficulty, a la G... table since FORTRAN
  1160. functions returning strings have extra arg.'s. Don't bother, since this only
  1161. causes a compiler warning to come up when one uses FCALLSCFUNn and CCALLSFFUNn
  1162. for the same function in the same source code. Something done by the experts in
  1163. debugging only.*/    
  1164.  
  1165. #define PROTOCCALLSFFUN0(F,UN,LN)                                              \
  1166. PU/**/F( CFC_(UN,LN))(CF_NULL_PROTO);                                          \
  1167. static _INT(2,U,F,CFFUN(UN),0)() {E/**/F  _INT(3,GZ,F,UN,LN)); X/**/F}
  1168.  
  1169. #define PROTOCCALLSFFUN1( T0,UN,LN,T1)                                         \
  1170.         PROTOCCALLSFFUN5 (T0,UN,LN,T1,CF_0,CF_0,CF_0,CF_0)
  1171. #define PROTOCCALLSFFUN2( T0,UN,LN,T1,T2)                                      \
  1172.         PROTOCCALLSFFUN5 (T0,UN,LN,T1,T2,CF_0,CF_0,CF_0)
  1173. #define PROTOCCALLSFFUN3( T0,UN,LN,T1,T2,T3)                                   \
  1174.         PROTOCCALLSFFUN5 (T0,UN,LN,T1,T2,T3,CF_0,CF_0)
  1175. #define PROTOCCALLSFFUN4( T0,UN,LN,T1,T2,T3,T4)                                \
  1176.         PROTOCCALLSFFUN5 (T0,UN,LN,T1,T2,T3,T4,CF_0)
  1177. #define PROTOCCALLSFFUN5( T0,UN,LN,T1,T2,T3,T4,T5)                             \
  1178.         PROTOCCALLSFFUN10(T0,UN,LN,T1,T2,T3,T4,T5,CF_0,CF_0,CF_0,CF_0,CF_0)
  1179. #define PROTOCCALLSFFUN6( T0,UN,LN,T1,T2,T3,T4,T5,T6)                          \
  1180.         PROTOCCALLSFFUN10(T0,UN,LN,T1,T2,T3,T4,T5,T6,CF_0,CF_0,CF_0,CF_0)
  1181. #define PROTOCCALLSFFUN7( T0,UN,LN,T1,T2,T3,T4,T5,T6,T7)                       \
  1182.         PROTOCCALLSFFUN10(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,CF_0,CF_0,CF_0)
  1183. #define PROTOCCALLSFFUN8( T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8)                    \
  1184.         PROTOCCALLSFFUN10(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,CF_0,CF_0)
  1185. #define PROTOCCALLSFFUN9( T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9)                 \
  1186.         PROTOCCALLSFFUN10(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,CF_0)
  1187.  
  1188. #ifndef __CF__KnR
  1189. #define PROTOCCALLSFFUN10(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA)              \
  1190. PU/**/T0(CFC_(UN,LN))(CF_NULL_PROTO);                                          \
  1191. static _INT(2,U,T0,CFFUN(UN),0)(UCF(T1,1,0) UCF(T2,2,1) UCF(T3,3,1) UCF(T4,4,1)  \
  1192.    UCF(T5,5,1) UCF(T6,6,1) UCF(T7,7,1) UCF(T8,8,1) UCF(T9,9,1) UCF(TA,A,1)     \
  1193.                          HCF(T1,1) HCF(T2,2) HCF(T3,3) HCF(T4,4) HCF(T5,5)     \
  1194.                          HCF(T6,6) HCF(T7,7) HCF(T8,8) HCF(T9,9) HCF(TA,A) )   \
  1195. {VCF(T1,1) VCF(T2,2) VCF(T3,3) VCF(T4,4) VCF(T5,5)                             \
  1196.  VCF(T6,6) VCF(T7,7) VCF(T8,8) VCF(T9,9) VCF(TA,A) E/**/T0                     \
  1197.  CCF(T1,1) CCF(T2,2) CCF(T3,3) CCF(T4,4) CCF(T5,5)                             \
  1198.  CCF(T6,6) CCF(T7,7) CCF(T8,8) CCF(T9,9) CCF(TA,A)                             \
  1199.  _INT(3,G,T0,UN,LN)CCCF(T1,1,0) CCCF(T2,2,1) CCCF(T3,3,1) CCCF(T4,4,1) CCCF(T5,5,1)\
  1200.                  CCCF(T6,6,1) CCCF(T7,7,1) CCCF(T8,8,1) CCCF(T9,9,1) CCCF(TA,A,1)\
  1201.                JCF(T1,1) JCF(T2,2) JCF(T3,3) JCF(T4,4) JCF(T5,5)               \
  1202.                JCF(T6,6) JCF(T7,7) JCF(T8,8) JCF(T9,9) JCF(TA,A));             \
  1203.  WCF(T1,A1,1) WCF(T2,A2,2) WCF(T3,A3,3) WCF(T4,A4,4) WCF(T5,A5,5)              \
  1204.  WCF(T6,A6,6) WCF(T7,A7,7) WCF(T8,A8,8) WCF(T9,A9,9) WCF(TA,AA,A) X/**/T0}
  1205. #else
  1206. #define PROTOCCALLSFFUN10(T0,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA)              \
  1207. PU/**/T0(CFC_(UN,LN))(CF_NULL_PROTO);                                          \
  1208. static _INT(2,U,T0,CFFUN(UN),0)(UUCF(T1,1,0) UUCF(T2,2,1) UUCF(T3,3,1) UUCF(T4,4,1)  \
  1209.     UUCF(T5,5,1) UUCF(T6,6,1) UUCF(T7,7,1) UUCF(T8,8,1) UUCF(T9,9,1) UUCF(TA,A,1)  \
  1210.                        HHCF(T1,1) HHCF(T2,2) HHCF(T3,3) HHCF(T4,4) HHCF(T5,5)  \
  1211.                        HHCF(T6,6) HHCF(T7,7) HHCF(T8,8) HHCF(T9,9) HHCF(TA,A)) \
  1212.  UUUCF(T1,1,0) UUUCF(T2,2,1) UUUCF(T3,3,1) UUUCF(T4,4,1) UUUCF(T5,5,1)         \
  1213.  UUUCF(T6,6,1) UUUCF(T7,7,1) UUUCF(T8,8,1) UUUCF(T9,9,1) UUUCF(TA,A,1)         \
  1214.            HHHCF(T1,1) HHHCF(T2,2) HHHCF(T3,3) HHHCF(T4,4) HHHCF(T5,5)         \
  1215.            HHHCF(T6,6) HHHCF(T7,7) HHHCF(T8,8) HHHCF(T9,9) HHHCF(TA,A);        \
  1216. {VCF(T1,1) VCF(T2,2) VCF(T3,3) VCF(T4,4) VCF(T5,5)                             \
  1217.  VCF(T6,6) VCF(T7,7) VCF(T8,8) VCF(T9,9) VCF(TA,A) E/**/T0                     \
  1218.  CCF(T1,1) CCF(T2,2) CCF(T3,3) CCF(T4,4) CCF(T5,5)                             \
  1219.  CCF(T6,6) CCF(T7,7) CCF(T8,8) CCF(T9,9) CCF(TA,A)                             \
  1220.  _INT(3,G,T0,UN,LN)CCCF(T1,1,0) CCCF(T2,2,1) CCCF(T3,3,1) CCCF(T4,4,1) CCCF(T5,5,1)\
  1221.                  CCCF(T6,6,1) CCCF(T7,7,1) CCCF(T8,8,1) CCCF(T9,9,1) CCCF(TA,A,1)\
  1222.                JCF(T1,1) JCF(T2,2) JCF(T3,3) JCF(T4,4) JCF(T5,5)               \
  1223.                JCF(T6,6) JCF(T7,7) JCF(T8,8) JCF(T9,9) JCF(TA,A) );            \
  1224.  WCF(T1,A1,1) WCF(T2,A2,2) WCF(T3,A3,3) WCF(T4,A4,4) WCF(T5,A5,5)              \
  1225.  WCF(T6,A6,6) WCF(T7,A7,7) WCF(T8,A8,8) WCF(T9,A9,9) WCF(TA,AA,A) X/**/T0}
  1226. #endif
  1227.  
  1228. /*-------------------------------------------------------------------------*/
  1229.  
  1230. /*               UTILITIES FOR FORTRAN TO CALL C ROUTINES                  */
  1231.  
  1232. #if defined(VAXC) && defined(vms)        /* To avoid %CC-I-PARAMNOTUSED. */
  1233. #pragma nostandard
  1234. #endif
  1235.  
  1236. #if defined(vmsFortran) || defined(CRAYFortran)
  1237. #define   DCF(TN,I)
  1238. #define  DDCF(TN,I)
  1239. #define DDDCF(TN,I)
  1240. #else
  1241. #define   DCF                HCF
  1242. #define  DDCF               HHCF
  1243. #define DDDCF              HHHCF
  1244. #endif
  1245.  
  1246. #define QCF(TN,I)    STR_/**/TN(1,Q,B/**/I, 0,0,0)
  1247. #define QLOGICAL( B)
  1248. #define QPLOGICAL(B)
  1249. #ifdef vmsFortran
  1250. #define QSTRINGV( B) char *B;
  1251. #else
  1252. #define QSTRINGV( B) char *B; unsigned int B/**/N;
  1253. #endif
  1254. #define QSTRING(  B) char *B=NULL;
  1255. #define QPSTRING( B) char *B=NULL;
  1256. #define QPSTRINGV    QSTRINGV
  1257.  
  1258. #define TCF(NAME,TN,I,M)   _SEP_(TN,M,COMMA) T/**/TN(NAME,A/**/I,B/**/I,C/**/I)
  1259. #define TBYTE(    M,A,B,D) *A
  1260. #define TDOUBLE(  M,A,B,D) *A
  1261. #define TFLOAT(   M,A,B,D) *A
  1262. #define TINT(     M,A,B,D) *A
  1263. #define TLOGICAL( M,A,B,D)  F2CLOGICAL(*A)
  1264. #define TLONG(    M,A,B,D) *A
  1265. #define TSHORT(   M,A,B,D) *A
  1266. #define TBYTEV(   M,A,B,D)  A
  1267. #define TDOUBLEV( M,A,B,D)  A
  1268. #define TFLOATV(  M,A,B,D)  VOIDP A
  1269. #define TINTV(    M,A,B,D)  A
  1270. #define TLOGICALV(M,A,B,D)  A
  1271. #define TLONGV(   M,A,B,D)  A
  1272. #define TSHORTV(  M,A,B,D)  A
  1273. #define TBYTEVV(  M,A,B,D)  A
  1274. #define TDOUBLEVV(M,A,B,D)  A
  1275. #define TFLOATVV( M,A,B,D)  VOIDP A
  1276. #define TINTVV(   M,A,B,D)  A
  1277. #define TLOGICALVV(M,A,B,D) A
  1278. #define TLONGVV(  M,A,B,D)  A
  1279. #define TSHORTVV( M,A,B,D)  A
  1280. #define TPBYTE(   M,A,B,D)  A
  1281. #define TPDOUBLE( M,A,B,D)  A
  1282. #define TPFLOAT(  M,A,B,D)  VOIDP A
  1283. #define TPINT(    M,A,B,D)  A
  1284. #define TPLOGICAL(M,A,B,D)  ((*A=F2CLOGICAL(*A)),A)
  1285. #define TPLONG(   M,A,B,D)  A
  1286. #define TPSHORT(  M,A,B,D)  A
  1287. #define TPVOID(   M,A,B,D)  A
  1288. #ifdef vmsFortran
  1289. #define TSTRING(  M,A,B,D) (!*(int *)A->dsc$a_pointer)?NULL:\
  1290. memchr(A->dsc$a_pointer,'\0',A->dsc$w_length)?A->dsc$a_pointer:\
  1291.                           ((B=malloc(A->dsc$w_length+1))[A->dsc$w_length]='\0',\
  1292.                   kill_trailing(memcpy(B,A->dsc$a_pointer,A->dsc$w_length),' '))
  1293. #define TSTRINGV( M,A,B,D)                                                     \
  1294.  (B=malloc((A->dsc$w_length+1)*A->dsc$l_m[0]), (void *)F2CSTRVCOPY(B,A))
  1295. #else
  1296. #ifdef CRAYFortran
  1297. #define TSTRING(  M,A,B,D) (!*(int *)_fcdtocp(A))?NULL:\
  1298. memchr(_fcdtocp(A),'\0',_fcdlen(A))?_fcdtocp(A):\
  1299.                           ((B=malloc(_fcdlen(A)+1))[_fcdlen(A)]='\0',          \
  1300.                             kill_trailing(memcpy(B,_fcdtocp(A),_fcdlen(A)),' '))
  1301. #define TSTRINGV( M,A,B,D) (B/**/N=num_elem(_fcdtocp(A),_fcdlen(A),M/**/_STRV_/**/A),             \
  1302.      (void *)vkill_trailing(f2cstrv(_fcdtocp(A),B=malloc(B/**/N*(_fcdlen(A)+1)),_fcdlen(A)+1,B/**/N*(_fcdlen(A)+1)),\
  1303.                             _fcdlen(A)+1,B/**/N*(_fcdlen(A)+1),' '))
  1304. #else
  1305. #define TSTRING(  M,A,B,D) (!*(int *)A)?NULL: memchr(A,'\0',D)?A:              \
  1306.                      (memcpy(B=malloc(D+1),A,D),B[D]='\0', kill_trailing(B,' '))
  1307. #define TSTRINGV( M,A,B,D) (B/**/N=num_elem(A,D,M/**/_STRV_/**/A),             \
  1308.      (void *)vkill_trailing(f2cstrv(A,B=malloc(B/**/N*(D+1)),D+1,B/**/N*(D+1)),\
  1309.                             D+1,B/**/N*(D+1),' '))
  1310. #endif
  1311. #endif
  1312. #define TPSTRING            TSTRING
  1313. #define TPSTRINGV           TSTRINGV
  1314. #define TCF_0(    M,A,B,D)
  1315.  
  1316. #define RCF(TN,I)        STR_/**/TN(3,R,A/**/I,B/**/I,C/**/I,0)
  1317. #define RLOGICAL( A,B,D)
  1318. #define RPLOGICAL(A,B,D) *A=C2FLOGICAL(*A);
  1319. #define RSTRING(  A,B,D) if (B) free(B);
  1320. #define RSTRINGV( A,B,D) free(B);
  1321. #ifdef vmsFortran
  1322. #define RPSTRING( A,B,D) if (B)                                              \
  1323.  memcpy(A->dsc$a_pointer,B,MIN(strlen(B),A->dsc$w_length)),                    \
  1324.  (A->dsc$w_length>strlen(B)?                                                   \
  1325.    memset(A->dsc$a_pointer+strlen(B),' ', A->dsc$w_length-strlen(B)):0),free(B);
  1326. #define RPSTRINGV(A,B,D) C2FSTRVCOPY(B,A), free(B);
  1327. #else
  1328. #ifdef CRAYFortran
  1329. #define RPSTRING( A,B,D) if (B)                                              \
  1330.  memcpy(_fcdtocp(A),B,MIN(strlen(B),_fcdlen(A))),  (_fcdlen(A)>strlen(B)?      \
  1331.    memset(_fcdtocp(A)+strlen(B),' ', _fcdlen(A)-strlen(B)):0),free(B);
  1332. #define RPSTRINGV(A,B,D)                                                     \
  1333.              c2fstrv(B,_fcdtocp(A),_fcdlen(A)+1,(_fcdlen(A)+1)*B/**/N), free(B);
  1334. #else
  1335. #define RPSTRING( A,B,D) if (B) memcpy(A,B,MIN(strlen(B),D)),                \
  1336.                   (D>strlen(B)?memset(A+strlen(B),' ', D-strlen(B)):0), free(B);
  1337. #define RPSTRINGV(A,B,D) c2fstrv(B,A,D+1,(D+1)*B/**/N), free(B);
  1338. #endif
  1339. #endif
  1340.  
  1341. #define FZBYTE(   UN,LN) INTEGER_BYTE     fcallsc(UN,LN)(
  1342. #define FZDOUBLE( UN,LN) DOUBLE_PRECISION fcallsc(UN,LN)(
  1343. #define FZINT(    UN,LN) int   fcallsc(UN,LN)(
  1344. #define FZLOGICAL(UN,LN) int   fcallsc(UN,LN)(
  1345. #define FZLONG(   UN,LN) long  fcallsc(UN,LN)(
  1346. #define FZSHORT(  UN,LN) short fcallsc(UN,LN)(
  1347. #define FZVOID(   UN,LN) void  fcallsc(UN,LN)(
  1348. #ifndef __CF__KnR
  1349. /* The void is req'd by the Apollo, to make this an ANSI function declaration.
  1350.    The Apollo promotes K&R float functions to double. */
  1351. #define FZFLOAT(  UN,LN) float fcallsc(UN,LN)(void
  1352. #ifdef vmsFortran
  1353. #define FZSTRING( UN,LN) void  fcallsc(UN,LN)(fstring *AS
  1354. #else
  1355. #ifdef CRAYFortran
  1356. #define FZSTRING( UN,LN) void  fcallsc(UN,LN)(_fcd     AS
  1357. #else
  1358. #define FZSTRING( UN,LN) void  fcallsc(UN,LN)(char    *AS, unsigned D0
  1359. #endif
  1360. #endif
  1361. #else
  1362. #ifndef sunFortran
  1363. #define FZFLOAT(  UN,LN) float fcallsc(UN,LN)(
  1364. #else
  1365. #define FZFLOAT(  UN,LN) FLOATFUNCTIONTYPE fcallsc(UN,LN)(
  1366. #endif
  1367. #if defined(vmsFortran) || defined(CRAYFortran)
  1368. #define FZSTRING( UN,LN) void  fcallsc(UN,LN)(AS
  1369. #else
  1370. #define FZSTRING( UN,LN) void  fcallsc(UN,LN)(AS, D0
  1371. #endif
  1372. #endif
  1373.  
  1374. #define FBYTE            FZBYTE
  1375. #define FDOUBLE          FZDOUBLE
  1376. #ifndef __CF_KnR
  1377. #define FFLOAT(  UN,LN)  float   fcallsc(UN,LN)(
  1378. #else
  1379. #define FFLOAT           FZFLOAT
  1380. #endif
  1381. #define FINT             FZINT
  1382. #define FLOGICAL         FZLOGICAL
  1383. #define FLONG            FZLONG
  1384. #define FSHORT           FZSHORT
  1385. #define FVOID            FZVOID
  1386. #define FSTRING(  UN,LN) FZSTRING(UN,LN),
  1387.  
  1388. #define FFINT
  1389. #define FFVOID
  1390. #ifdef vmsFortran
  1391. #define FFSTRING          fstring *AS; 
  1392. #else
  1393. #ifdef CRAYFortran
  1394. #define FFSTRING          _fcd     AS;
  1395. #else
  1396. #define FFSTRING          char    *AS; unsigned D0;
  1397. #endif
  1398. #endif
  1399.  
  1400. #define LINT              A0=
  1401. #define LSTRING           A0=
  1402. #define LVOID                        
  1403.  
  1404. #define KINT            
  1405. #define KVOID
  1406. /* KSTRING copies the string into the position provided by the caller. */
  1407. #ifdef vmsFortran
  1408. #define KSTRING                                                                \
  1409.  memcpy(AS->dsc$a_pointer,A0, MIN(AS->dsc$w_length,(A0==NULL?0:strlen(A0))) ); \
  1410.  AS->dsc$w_length>(A0==NULL?0:strlen(A0))?                                     \
  1411.   memset(AS->dsc$a_pointer+(A0==NULL?0:strlen(A0)),' ',                        \
  1412.          AS->dsc$w_length-(A0==NULL?0:strlen(A0))):0;
  1413. #else
  1414. #ifdef CRAYFortran
  1415. #define KSTRING                                                                \
  1416.  memcpy(_fcdtocp(AS),A0, MIN(_fcdlen(AS),(A0==NULL?0:strlen(A0))) );           \
  1417.  _fcdlen(AS)>(A0==NULL?0:strlen(A0))?                                          \
  1418.   memset(_fcdtocp(AS)+(A0==NULL?0:strlen(A0)),' ',                             \
  1419.          _fcdlen(AS)-(A0==NULL?0:strlen(A0))):0;
  1420. #else
  1421. #define KSTRING          memcpy(AS,A0, MIN(D0,(A0==NULL?0:strlen(A0))) );      \
  1422.                  D0>(A0==NULL?0:strlen(A0))?memset(AS+(A0==NULL?0:strlen(A0)), \
  1423.                                             ' ', D0-(A0==NULL?0:strlen(A0))):0;
  1424. #endif
  1425. #endif
  1426.  
  1427. /* Note that K.. and I.. can't be combined since K.. has to access data before
  1428. R.., in order for functions returning strings which are also passed in as
  1429. arguments to work correctly. Note that R.. frees and hence may corrupt the
  1430. string. */
  1431. #define IBYTE          return A0;
  1432. #define IDOUBLE        return A0;
  1433. #ifndef sunFortran
  1434. #define IFLOAT         return A0;
  1435. #else
  1436. #define IFLOAT         RETURNFLOAT(A0);
  1437. #endif
  1438. #define IINT           return A0;
  1439. #define ILOGICAL       return C2FLOGICAL(A0);
  1440. #define ILONG          return A0;
  1441. #define ISHORT         return A0;
  1442. #define ISTRING        return   ;
  1443. #define IVOID          return   ;
  1444.  
  1445. #if defined(VAXC) && defined(vms)        /* Have avoided %CC-I-PARAMNOTUSED. */
  1446. #pragma standard
  1447. #endif
  1448.  
  1449. #define FCALLSCSUB0( CN,UN,LN)             FCALLSCFUN0(VOID,CN,UN,LN)
  1450. #define FCALLSCSUB1( CN,UN,LN,T1)          FCALLSCFUN1(VOID,CN,UN,LN,T1)
  1451. #define FCALLSCSUB2( CN,UN,LN,T1,T2)       FCALLSCFUN2(VOID,CN,UN,LN,T1,T2)
  1452. #define FCALLSCSUB3( CN,UN,LN,T1,T2,T3)    FCALLSCFUN3(VOID,CN,UN,LN,T1,T2,T3)
  1453. #define FCALLSCSUB4( CN,UN,LN,T1,T2,T3,T4) FCALLSCFUN4(VOID,CN,UN,LN,T1,T2,T3,T4)
  1454. #define FCALLSCSUB5( CN,UN,LN,T1,T2,T3,T4,T5)                \
  1455.     FCALLSCFUN5(VOID,CN,UN,LN,T1,T2,T3,T4,T5)
  1456. #define FCALLSCSUB6( CN,UN,LN,T1,T2,T3,T4,T5,T6)             \
  1457.     FCALLSCFUN6(VOID,CN,UN,LN,T1,T2,T3,T4,T5,T6)       
  1458. #define FCALLSCSUB7( CN,UN,LN,T1,T2,T3,T4,T5,T6,T7)          \
  1459.     FCALLSCFUN7(VOID,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7)
  1460. #define FCALLSCSUB8( CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8)       \
  1461.     FCALLSCFUN8(VOID,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8)
  1462. #define FCALLSCSUB9( CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9)    \
  1463.     FCALLSCFUN9(VOID,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9)
  1464. #define FCALLSCSUB10(CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA) \
  1465.    FCALLSCFUN10(VOID,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA)
  1466.  
  1467. #define FCALLSCFUN1( T0,CN,UN,LN,T1)            \
  1468.         FCALLSCFUN5 (T0,CN,UN,LN,T1,CF_0,CF_0,CF_0,CF_0)
  1469. #define FCALLSCFUN2( T0,CN,UN,LN,T1,T2)         \
  1470.         FCALLSCFUN5 (T0,CN,UN,LN,T1,T2,CF_0,CF_0,CF_0)
  1471. #define FCALLSCFUN3( T0,CN,UN,LN,T1,T2,T3)      \
  1472.         FCALLSCFUN5 (T0,CN,UN,LN,T1,T2,T3,CF_0,CF_0)
  1473. #define FCALLSCFUN4( T0,CN,UN,LN,T1,T2,T3,T4)   \
  1474.         FCALLSCFUN5 (T0,CN,UN,LN,T1,T2,T3,T4,CF_0)
  1475. #define FCALLSCFUN5( T0,CN,UN,LN,T1,T2,T3,T4,T5)\
  1476.         FCALLSCFUN10(T0,CN,UN,LN,T1,T2,T3,T4,T5,CF_0,CF_0,CF_0,CF_0,CF_0)
  1477. #define FCALLSCFUN6( T0,CN,UN,LN,T1,T2,T3,T4,T5,T6)          \
  1478.         FCALLSCFUN10(T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,CF_0,CF_0,CF_0,CF_0)
  1479. #define FCALLSCFUN7( T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7)       \
  1480.         FCALLSCFUN10(T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,CF_0,CF_0,CF_0)
  1481. #define FCALLSCFUN8( T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8)    \
  1482.         FCALLSCFUN10(T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,CF_0,CF_0)
  1483. #define FCALLSCFUN9( T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9) \
  1484.         FCALLSCFUN10(T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,CF_0)
  1485.  
  1486. #ifndef __CF__KnR
  1487. #define FCALLSCFUN0(T0,CN,UN,LN)                                               \
  1488. FZ/**/T0(UN,LN)) {_INT(2,U,T0,A0,0); _INT(0,L,T0,0,0) CN(); _INT(0,K,T0,0,0) I/**/T0}
  1489.  
  1490. #define FCALLSCFUN10(T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA)                \
  1491. F/**/T0(UN,LN)NCF(T1,1,0) NCF(T2,2,1) NCF(T3,3,1) NCF(T4,4,1) NCF(T5,5,1)      \
  1492.               NCF(T6,6,1) NCF(T7,7,1) NCF(T8,8,1) NCF(T9,9,1) NCF(TA,A,1)      \
  1493.                         DCF(T1,1) DCF(T2,2) DCF(T3,3) DCF(T4,4) DCF(T5,5)      \
  1494.                         DCF(T6,6) DCF(T7,7) DCF(T8,8) DCF(T9,9) DCF(TA,A) )    \
  1495.  {_INT(2,U,T0,A0,0); QCF(T1,1) QCF(T2,2) QCF(T3,3) QCF(T4,4) QCF(T5,5)           \
  1496.                QCF(T6,6) QCF(T7,7) QCF(T8,8) QCF(T9,9) QCF(TA,A)               \
  1497.  _INT(0,L,T0,0,0) CN(TCF(LN,T1,1,0) TCF(LN,T2,2,1) TCF(LN,T3,3,1) TCF(LN,T4,4,1) \
  1498.     TCF(LN,T5,5,1) TCF(LN,T6,6,1) TCF(LN,T7,7,1) TCF(LN,T8,8,1) TCF(LN,T9,9,1) \
  1499.     TCF(LN,TA,A,1)); _INT(0,K,T0,0,0) RCF(T1,1) RCF(T2,2) RCF(T3,3) RCF(T4,4)    \
  1500.            RCF(T5,5) RCF(T6,6) RCF(T7,7) RCF(T8,8) RCF(T9,9) RCF(TA,A) I/**/T0}
  1501. #else
  1502. #define FCALLSCFUN0(T0,CN,UN,LN) FZ/**/T0(UN,LN)) _INT(0,FF,T0,0,0)              \
  1503. {_INT(2,U,T0,A0,0); _INT(0,L,T0,0,0) CN(); _INT(0,K,T0,0,0) I/**/T0}
  1504.  
  1505. #define FCALLSCFUN10(T0,CN,UN,LN,T1,T2,T3,T4,T5,T6,T7,T8,T9,TA)                \
  1506. F/**/T0(UN,LN)NNCF(T1,1,0) NNCF(T2,2,1) NNCF(T3,3,1) NNCF(T4,4,1) NNCF(T5,5,1) \
  1507.               NNCF(T6,6,1) NNCF(T7,7,1) NNCF(T8,8,1) NNCF(T9,9,1) NNCF(TA,A,1) \
  1508.    DDCF(T1,1) DDCF(T2,2) DDCF(T3,3) DDCF(T4,4) DDCF(T5,5)                      \
  1509.    DDCF(T6,6) DDCF(T7,7) DDCF(T8,8) DDCF(T9,9) DDCF(TA,A) )  _INT(0,FF,T0,0,0)   \
  1510.  NNNCF(T1,1,0) NNNCF(T2,2,1) NNNCF(T3,3,1) NNNCF(T4,4,1) NNNCF(T5,5,1)         \
  1511.  NNNCF(T6,6,1) NNNCF(T7,7,1) NNNCF(T8,8,1) NNNCF(T9,9,1) NNNCF(TA,A,1)         \
  1512.  DDDCF(T1,1) DDDCF(T2,2) DDDCF(T3,3) DDDCF(T4,4) DDDCF(T5,5)                   \
  1513.  DDDCF(T6,6) DDDCF(T7,7) DDDCF(T8,8) DDDCF(T9,9) DDDCF(TA,A);                  \
  1514.  {_INT(2,U,T0,A0,0); QCF(T1,1) QCF(T2,2) QCF(T3,3) QCF(T4,4) QCF(T5,5)           \
  1515.                QCF(T6,6) QCF(T7,7) QCF(T8,8) QCF(T9,9) QCF(TA,A)               \
  1516.  _INT(0,L,T0,0,0) CN( TCF(LN,T1,1,0) TCF(LN,T2,2,1) TCF(LN,T3,3,1)               \
  1517.                     TCF(LN,T4,4,1) TCF(LN,T5,5,1) TCF(LN,T6,6,1)               \
  1518.      TCF(LN,T7,7,1) TCF(LN,T8,8,1) TCF(LN,T9,9,1) TCF(LN,TA,A,1));             \
  1519.  _INT(0,K,T0,0,0) RCF(T1,1) RCF(T2,2) RCF(T3,3) RCF(T4,4) RCF(T5,5)              \
  1520.                 RCF(T6,6) RCF(T7,7) RCF(T8,8) RCF(T9,9) RCF(TA,A) I/**/T0}
  1521. #endif
  1522.  
  1523. #endif   /* VAX VMS or Ultrix, Mips, CRAY, Sun, Apollo, HP9000, LynxOS, IBMR2.
  1524.             f2c, NAG f90. */
  1525. #endif     /* __CFORTRAN_LOADED */
  1526.